Spaces:
Sleeping
Sleeping
Commit ·
60a5684
1
Parent(s): 236cdf9
Fix detection-type menu navigation: switch mode and dashboard without reload loop
Browse files- static/js/app.js +18 -4
- templates/index.html +1 -1
static/js/app.js
CHANGED
|
@@ -26,12 +26,27 @@ function applyDetectionTypeToUI(type) {
|
|
| 26 |
typeSel.dispatchEvent(new Event('change'));
|
| 27 |
}
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
// ---- Detection type selection buttons ----
|
| 30 |
document.getElementById('btn-type-change')?.addEventListener('click', () => {
|
| 31 |
-
|
| 32 |
});
|
| 33 |
document.getElementById('btn-type-landslide')?.addEventListener('click', () => {
|
| 34 |
-
|
| 35 |
});
|
| 36 |
|
| 37 |
function showError(id, msg) {
|
|
@@ -108,8 +123,7 @@ function handlePostAuthNavigation() {
|
|
| 108 |
// then auto-redirect after the menu is shown.
|
| 109 |
if (preferred) {
|
| 110 |
setTimeout(() => {
|
| 111 |
-
|
| 112 |
-
loadHistory();
|
| 113 |
}, 150);
|
| 114 |
}
|
| 115 |
}
|
|
|
|
| 26 |
typeSel.dispatchEvent(new Event('change'));
|
| 27 |
}
|
| 28 |
|
| 29 |
+
function pathForDetectionType(type) {
|
| 30 |
+
return type === 'landslide_detection' ? '/detect/landslide' : '/detect/change';
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function navigateToDetectionType(type, replace = false) {
|
| 34 |
+
applyDetectionTypeToUI(type);
|
| 35 |
+
const targetPath = pathForDetectionType(type);
|
| 36 |
+
if ((window.location.pathname || '') !== targetPath) {
|
| 37 |
+
const fn = replace ? 'replaceState' : 'pushState';
|
| 38 |
+
window.history[fn]({}, '', targetPath);
|
| 39 |
+
}
|
| 40 |
+
showView('dashboard');
|
| 41 |
+
loadHistory();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
// ---- Detection type selection buttons ----
|
| 45 |
document.getElementById('btn-type-change')?.addEventListener('click', () => {
|
| 46 |
+
navigateToDetectionType('change_detection');
|
| 47 |
});
|
| 48 |
document.getElementById('btn-type-landslide')?.addEventListener('click', () => {
|
| 49 |
+
navigateToDetectionType('landslide_detection');
|
| 50 |
});
|
| 51 |
|
| 52 |
function showError(id, msg) {
|
|
|
|
| 123 |
// then auto-redirect after the menu is shown.
|
| 124 |
if (preferred) {
|
| 125 |
setTimeout(() => {
|
| 126 |
+
navigateToDetectionType(preferred, true);
|
|
|
|
| 127 |
}, 150);
|
| 128 |
}
|
| 129 |
}
|
templates/index.html
CHANGED
|
@@ -392,6 +392,6 @@
|
|
| 392 |
</div>
|
| 393 |
</div>
|
| 394 |
|
| 395 |
-
<script src="/static/js/app.js?v=
|
| 396 |
</body>
|
| 397 |
</html>
|
|
|
|
| 392 |
</div>
|
| 393 |
</div>
|
| 394 |
|
| 395 |
+
<script src="/static/js/app.js?v=29"></script>
|
| 396 |
</body>
|
| 397 |
</html>
|