@@ -1141,6 +1141,9 @@ under the License.
if (!requireAuth()) {
// Will redirect to login
} else {
+ // Clear history state on startup (can happen when reloading with popup open)
+ if (history.state?.modal) history.back();
+
initSidebarWithRole();
updateUserInfo();
init();
@@ -1164,11 +1167,19 @@ under the License.
currentPrefix += '/';
}
}
+ } else {
+ currentBucket = "";
+ currentPrefix = "";
}
await loadBuckets();
}
-
+
+ // Rerun init() on hash change to allow for back/forward when browsing a bucket.
+ window.addEventListener('hashchange', async () => {
+ await init();
+ });
+
// ============================================
// Logout
// ============================================
diff --git a/webui/web/js/app.js b/webui/web/js/app.js
index 7e25253f..a4790141 100644
--- a/webui/web/js/app.js
+++ b/webui/web/js/app.js
@@ -129,13 +129,26 @@ function openModal(modalId) {
// Focus first input
const firstInput = modal.querySelector('input:not([readonly]), select');
if (firstInput) setTimeout(() => firstInput.focus(), 100);
+
+ // Push to history state so the back button can close the modal
+ history.pushState({ modal: true }, '');
}
}
-function closeModal(modalId) {
+let navigatingBack = false
+
+// Close the currently opened modal, manually popping the modal
+// history state if the modal was closed manually (default). In the
+// case where the modal was closed due to navigating back, the state
+// is already popped and we can skip it.
+function closeModal(modalId, popState = true) {
const modal = document.getElementById(modalId);
if (modal) {
modal.classList.add('hidden');
+ if (popState && history.state?.modal) {
+ navigatingBack = true;
+ history.back();
+ }
}
}
@@ -145,6 +158,24 @@ function closeAllModals() {
});
}
+function closeModalsOnNavigation() {
+ Array.from(document.getElementsByClassName('modal')).forEach((modal) => {
+ if (!modal.classList.contains('hidden')) {
+ closeModal(modal.getAttribute('id'), false);
+ }
+ })
+}
+
+// Catch the back button to close the open modal, if any is open.
+window.addEventListener('popstate', (e) => {
+ if (navigatingBack) {
+ navigatingBack = false;
+ return;
+ }
+
+ closeModalsOnNavigation();
+});
+
// Close modals on Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeAllModals();
diff --git a/webui/web/users.html b/webui/web/users.html
index 668315be..3f5b6772 100644
--- a/webui/web/users.html
+++ b/webui/web/users.html
@@ -209,7 +209,7 @@ under the License.
-
+
@@ -298,7 +298,7 @@ under the License.
-
+
@@ -324,7 +324,7 @@ under the License.