From 235504a3fb625c5e0c09a8cabbe5dcf5befc0a84 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 12 Jun 2024 10:43:48 +0800 Subject: [PATCH] fix #293. stay at MAP page. Remove calling of copyPending....... --- src/components/Navbar.vue | 14 ++++++++++++-- src/module/alertModal.js | 7 ++----- src/stores/pageAdmin.js | 13 +++++++------ src/views/MainContainer.vue | 1 - 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 921ce92..24dc5a7 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -137,6 +137,7 @@ export default { 'activePage', 'pendingActivePage', 'activePageComputedByRoute', + 'shouldKeepPreviousPage', ]), }, watch: { @@ -146,7 +147,13 @@ export default { }, activePageComputedByRoute (newVal) { // console.log('activePageComputedByRoute newVal', newVal); - } + }, + activePage: function(newVal){ + // console.log('watch activePage', this.activePage); + }, + pendingActivePage: function(newVal){ + // console.log('watch pendingActivePage', this.pendingActivePage); + }, }, mounted() { this.handleNavItemBtn(); @@ -259,7 +266,10 @@ export default { // so here we need to save to a pending state // 前端無法確定用戶稍後會按下彈窗上的哪個按鈕(取消還是確認、儲存), // 因此我們需要將其保存到待處理狀態 - this.setPendingActivePage(valueToSet); + if(!this.shouldKeepPreviousPage) { // 若使用者不是按下取消按鈕或是點選按鈕時 + this.setPendingActivePage(valueToSet); + } + return valueToSet; }, diff --git a/src/module/alertModal.js b/src/module/alertModal.js index b8ee383..29fbae6 100644 --- a/src/module/alertModal.js +++ b/src/module/alertModal.js @@ -55,11 +55,11 @@ export async function saveFilter(addFilterId, next = null) { fileName = ''; return true; } else { // 點擊取消或空白處,為存檔失敗。 - // console.log("PageAdminStore.activePage", PageAdminStore.activePage); pageAdminStore.keepPreviousPage(); + // console.log("現在 pageAdminStore.activePage", pageAdminStore.activePage); // Not every time we have nontrivial next value - next !== null ? next() : 1; + next !== null ? next(false) : 1; return false; } } @@ -117,9 +117,6 @@ export async function leaveFilter(next, addFilterId, toPath, logOut) { await saveFilter(addFilterId, next); } - // Handle page admin issue - pageAdminStore.copyPendingPageToActivePage(); - logOut ? logOut() : next(toPath); } else if(result.dismiss === 'cancel') { // console.log('popup cancel case', ); diff --git a/src/stores/pageAdmin.js b/src/stores/pageAdmin.js index 03882e7..0354f00 100644 --- a/src/stores/pageAdmin.js +++ b/src/stores/pageAdmin.js @@ -1,5 +1,6 @@ import { defineStore } from "pinia"; import { mapPageNameToCapitalUnifiedName } from "../utils/pageUtils"; +const printPageAdiminLog = false; // There are at least two ways to trigger a page navigation: // clicking the navigation button and refreshing the page. @@ -21,7 +22,7 @@ export default defineStore('pageAdminStore', { setActivePageComputedByRoute(routeMatched){ if (routeMatched.length && routeMatched[routeMatched.length - 1] && routeMatched[routeMatched.length - 1].name) { - // console.log('setActivePageComputedByRoute()', mapPageNameToCapitalUnifiedName(routeMatched[routeMatched.length - 1].name)); + printPageAdiminLog && console.log('setActivePageComputedByRoute()', mapPageNameToCapitalUnifiedName(routeMatched[routeMatched.length - 1].name)); this.activePageComputedByRoute = mapPageNameToCapitalUnifiedName( routeMatched[routeMatched.length - 1].name); } @@ -32,7 +33,7 @@ export default defineStore('pageAdminStore', { * @param {string} activePage */ setActivePage(activePage) { - // console.log("setActivePage", activePage) + printPageAdiminLog && console.log("setActivePage", activePage) this.activePage = mapPageNameToCapitalUnifiedName(activePage); }, /** @@ -61,7 +62,7 @@ export default defineStore('pageAdminStore', { * Copy(transit) the value of pendingActivePage to activePage */ copyPendingPageToActivePage() { - // console.log('pinia copying this.pendingActivePage', this.pendingActivePage); + printPageAdiminLog && console.log('pinia copying this.pendingActivePage', this.pendingActivePage); this.activePage = this.pendingActivePage; }, /** @@ -72,7 +73,7 @@ export default defineStore('pageAdminStore', { * @param {string} pendingActivePage */ setPendingActivePage(argPendingActivePage) { - // console.log('pinia setting this.pendingActivePage', this.pendingActivePage); + printPageAdiminLog && console.log('pinia setting this.pendingActivePage', this.pendingActivePage); this.pendingActivePage = mapPageNameToCapitalUnifiedName(argPendingActivePage); }, /** @@ -87,7 +88,7 @@ export default defineStore('pageAdminStore', { * instead, we apply the previous page. */ keepPreviousPage() { - // console.log('pinia keeping this.previousPage', this.previousPage); + printPageAdiminLog && console.log('pinia keeping this.previousPage', this.previousPage); this.activePage = this.previousPage; this.shouldKeepPreviousPage = true; }, @@ -95,7 +96,7 @@ export default defineStore('pageAdminStore', { * Clean up the state of the boolean related to modal showing phase */ clearShouldKeepPreviousPageBoolean(){ - // console.log('clearShouldKeepPreviousPageBoolean()'); + printPageAdiminLog && console.log('clearShouldKeepPreviousPageBoolean()'); this.shouldKeepPreviousPage = false; }, }, diff --git a/src/views/MainContainer.vue b/src/views/MainContainer.vue index 5dfa85b..1f6de5c 100644 --- a/src/views/MainContainer.vue +++ b/src/views/MainContainer.vue @@ -64,7 +64,6 @@ export default { beforeRouteUpdate(to, from, next) { // console.log("beforeRouteUpdate", from.name, "to:", to.name); this.setPrevioiusPage(from.name); - this.setActivePageComputedByRoute(to.matched); // 離開 Map 頁時判斷是否有無資料和需要存檔 if ((from.name === 'Map' || from.name === 'CheckMap') && this.tempFilterId) {