Add feature to router: Block navigation
We want to use that for optimistic updates. While saving a comment we
don't want the user to leave the page, neither navigate to another page
within the app, nor close the browser tab.
Ultimately this can be used for all ongoing write requests. It is
implemented in a generic way.
Release-Notes: skip
Google-Bug-Id: b/262228572
Change-Id: Iefd3e9ca84730f6ade5b68a9c6364d95150b7b90
diff --git a/polygerrit-ui/app/elements/core/gr-navigation/gr-navigation.ts b/polygerrit-ui/app/elements/core/gr-navigation/gr-navigation.ts
index 4af24cc..94241ea 100644
--- a/polygerrit-ui/app/elements/core/gr-navigation/gr-navigation.ts
+++ b/polygerrit-ui/app/elements/core/gr-navigation/gr-navigation.ts
@@ -26,4 +26,22 @@
* page.redirect() eventually just calls `window.history.replaceState()`.
*/
replaceUrl(url: string): void;
+
+ /**
+ * You can ask the router to block all navigation to other pages for a while,
+ * e.g. while there are unsaved comments. You must make sure to call
+ * `releaseNavigation()` with the same string shortly after to unblock the
+ * router.
+ *
+ * The provided reason must be non-empty.
+ */
+ blockNavigation(reason: string): void;
+
+ /**
+ * See `blockNavigation()`.
+ *
+ * This API is not counting. If you block navigation with the same reason
+ * multiple times, then one release call will unblock.
+ */
+ releaseNavigation(reason: string): void;
}