Files
lucia-frontend/src/stores/pageAdmin.js
2026-03-06 13:25:00 +08:00

105 lines
3.9 KiB
JavaScript

import { defineStore } from "pinia";
import { mapPageNameToCapitalUnifiedName } from "../utils/pageUtils";
const printPageAdminLog = false;
// There are at least two ways to trigger a page navigation:
// clicking the navigation button and refreshing the page.
// Therefore, we need to handle page transitions caused by both of these methods.
// 至少有兩種方式引起畫面的導向: 點選導覽按鈕與重新整理網頁
// 因此至少要處理這兩種方式所引起的畫面切換
export const usePageAdminStore = defineStore('pageAdminStore', {
state: () => ({
activePage: 'MAP',
previousPage: 'MAP',
pendingActivePage: 'FILES',
isPagePending: false,
shouldKeepPreviousPage: false, // false -- meaning modal is not pressed as "NO"
activePageComputedByRoute: "MAP",
currentMapFile: '',
}),
getters: {
},
actions: {
setActivePageComputedByRoute(routeMatched){
if (routeMatched.length && routeMatched[routeMatched.length - 1]
&& routeMatched[routeMatched.length - 1].name) {
printPageAdminLog && console.log('setActivePageComputedByRoute()', mapPageNameToCapitalUnifiedName(routeMatched[routeMatched.length - 1].name));
this.activePageComputedByRoute = mapPageNameToCapitalUnifiedName(
routeMatched[routeMatched.length - 1].name);
}
},
/**
* Set Active Page; the page which the user is currently visiting
* @param {string} activePage
*/
setActivePage(activePage) {
printPageAdminLog && console.log("setActivePage", activePage)
this.activePage = mapPageNameToCapitalUnifiedName(activePage);
},
/**
* Specify previous page state value.
* @param {string} prevPage
*/
setPreviousPage(prevPage) {
this.previousPage = mapPageNameToCapitalUnifiedName(prevPage);
},
/**
* Set the previous(usually current) pages to the ones we just decide.
*/
setPreviousPageUsingActivePage() {
this.previousPage = this.activePage;
},
/**
* Set the boolean value of status of pending state of the pate
* For the control of Swal popup
* @param {boolean} boolVal
*/
setIsPagePendingBoolean(boolVal) {
this.isPagePending = boolVal;
},
/**
* Copy(transit) the value of pendingActivePage to activePage
*/
copyPendingPageToActivePage() {
printPageAdminLog && console.log('pinia copying this.pendingActivePage', this.pendingActivePage);
this.activePage = this.pendingActivePage;
},
/**
* Set Pending active Page, meaning we are not sure if user will chang her mind later on.
* Also, start pending state.
* Often, user triggers the modal and the pending state starts.
* Note: String conversion is needed. For Example, CheckMap is converted into MAP
* @param {string} pendingActivePage
*/
setPendingActivePage(argPendingActivePage) {
printPageAdminLog && console.log('pinia setting this.pendingActivePage', this.pendingActivePage);
this.pendingActivePage = mapPageNameToCapitalUnifiedName(argPendingActivePage);
},
/**
* Set Pending active Page to empty string; we call this right after we just decide an active page.
* Also, stop pending state.
*/
clearPendingActivePage(){
this.pendingActivePage = '';
},
/**
* When user dismiss the popup modal, we don't apply the new page,
* instead, we apply the previous page.
*/
keepPreviousPage() {
printPageAdminLog && console.log('pinia keeping this.previousPage', this.previousPage);
this.activePage = this.previousPage;
this.shouldKeepPreviousPage = true;
},
/**
* Clean up the state of the boolean related to modal showing phase
*/
clearShouldKeepPreviousPageBoolean(){
printPageAdminLog && console.log('clearShouldKeepPreviousPageBoolean()');
this.shouldKeepPreviousPage = false;
},
setCurrentMapFile(fileName){
this.currentMapFile = fileName;
},
},
})