diff --git a/src/App.vue b/src/App.vue index f92b4b7..991ac28 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,5 +5,5 @@ diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 7ace95c..50b6236 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -2,7 +2,7 @@ diff --git a/src/module/alertModal.js b/src/module/alertModal.js index c0f51f6..9fabbd7 100644 --- a/src/module/alertModal.js +++ b/src/module/alertModal.js @@ -2,6 +2,7 @@ import Swal from 'sweetalert2'; import AllMapDataStore from '@/stores/allMapData.js'; import ConformanceStore from '@/stores/conformance.js'; import FilesStore from '@/stores/files.js'; +import PageAdminStore from '@/stores/pageAdmin.js'; const customClass = { container: '!z-[99999]', @@ -78,6 +79,8 @@ export async function savedSuccessfully(value) { */ export async function leaveFilter(next, addFilterId, toPath, logOut) { const allMapDataStore = AllMapDataStore(); + const pageAdminStore = PageAdminStore(); + const result = await Swal.fire({ title: 'SAVE YOUR FILTER?', html: 'If you want to continue using this filter in any other page, please select [Yes].', @@ -89,22 +92,38 @@ export async function leaveFilter(next, addFilterId, toPath, logOut) { showCancelButton: true, cancelButtonText: 'No', cancelButtonColor: '#94a3b8', - customClass: customClass - }) + customClass: customClass, + }); + if(result.isConfirmed) { if(allMapDataStore.createFilterId) { await allMapDataStore.updataFilter(); - if(allMapDataStore.isUpdataFilter) await savedSuccessfully(allMapDataStore.filterName); + if(allMapDataStore.isUpdataFilter) { + await savedSuccessfully(allMapDataStore.filterName); + } } else { await saveFilter(addFilterId); } + + // Handle page admin issue + pageAdminStore.copyPendingPageToActivePage(); + logOut ? logOut() : next(toPath); } else if(result.dismiss === 'cancel') { + // Handle page admin issue + pageAdminStore.keepPreviousPage(); + allMapDataStore.tempFilterId = null; logOut ? logOut() : next(toPath); } else if(result.dismiss === 'backdrop') { + // Handle page admin issue + pageAdminStore.keepPreviousPage(); + logOut ? null : next(false); } + + // In any cases, execute the following + pageAdminStore.clearPendingActivePage(); }; /** * Conformance Saved diff --git a/src/stores/pageAdmin.js b/src/stores/pageAdmin.js new file mode 100644 index 0000000..124489a --- /dev/null +++ b/src/stores/pageAdmin.js @@ -0,0 +1,73 @@ +import { defineStore } from "pinia"; + +export default defineStore('pageAdminStore', { + state: () => ({ + activePage: 'FILES', + activeSubPage: 'ALL', + previousPage: 'FILES', + previousSubPage: 'ALL', + pendingActivePage: '', + pendingActiveSubPage: '', + isPending: false, + }), + getters: { + }, + actions: { + /** + * Set Active Page; the page which the user is currently visiting + * @param {string} activePage + * @param {string} activeSubPage + */ + setActivePage(activePage, activeSubpage) { + console.log("setActivePage:", activePage, activeSubPage); + this.activePage = activePage; + this.activeSubPage = activeSubPage; + }, + /** + * Set the previous(usually current) page because the user might change her mind when navigating. + * @param {string} previoiusPage + * @param {string} previoiusSubPage + */ + setPrevioiusPage(previoiusPage, previousSubPage) { + this.previoiusPage = previoiusPage; + this.previoiusSubPage = previousSubPage; + }, + /** + * Copy the value of pendingActivePage to activePage + */ + copyPendingPageToActivePage() { + console.log("Copy the value of pendingActivePage to activePage\nCopying:", this.pendingActivePage, this.pendingActiveSubPage) + this.activePage = this.pendingActivePage; + this.activeSubPage = this.pendingActiveSubPage; + }, + /** + * 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. + * @param {string} pendingActivePage + */ + setPendingActivePage(argPendingActivePage, argPendingActiveSubPage) { + this.pendingActivePage = argPendingActivePage; + this.pendingActiveSubPage = argPendingActiveSubPage; + this.isPending = true; + }, + /** + * Set Pending active Page to empty string; we call this right after we just decide an activePage. + * Also, stop pending state. + */ + clearPendingActivePage(){ + this.pendingActivePage = ''; + this.pendingActiveSubPage = ''; + this.isPending = false; + }, + /** + * When user dismiss the popup modal, we don't apply the new page, + * instead, we apply the previous page. + */ + keepPreviousPage() { + this.activePage = this.previousPage; + this.activeSubPage = this.previousSubPage; + this.isPending = false; + } + }, +}) \ No newline at end of file diff --git a/src/views/Login/index.vue b/src/views/Login/index.vue index 02d46f6..a255c4f 100644 --- a/src/views/Login/index.vue +++ b/src/views/Login/index.vue @@ -89,7 +89,9 @@ export default { */ changeHandler(event) { let inputValue = event.target.value; - if(inputValue !== '') this.isInvalid = false; + if(inputValue !== '') { + this.isInvalid = false; + } }, }, }; diff --git a/src/views/MainContainer.vue b/src/views/MainContainer.vue index e0eea52..8a03f6c 100644 --- a/src/views/MainContainer.vue +++ b/src/views/MainContainer.vue @@ -10,7 +10,7 @@