diff --git a/resources/js/router/index.js b/resources/js/router/index.js index b1035c5..8e5e381 100644 --- a/resources/js/router/index.js +++ b/resources/js/router/index.js @@ -368,17 +368,22 @@ const router = createRouter({ // export let activeRoutes = []; -router.beforeEach(async (to, from, next) => { - // BC Start - // activeRoutes = []; - // to.matched.forEach((record) => { - // console.log(record.routeName); - // activeRoutes.push(record); - // }); +let routerLoadingTimeout = null; +router.beforeEach(async (to, from, next) => { const userStore = useUserStore(); const applicationStore = useApplicationStore(); + if (routerLoadingTimeout != null) { + clearTimeout(routerLoadingTimeout); + routerLoadingTimeout = null; + } + + routerLoadingTimeout = window.setTimeout(() => { + routerLoadingTimeout = null; + applicationStore.setRouterLoading(true); + }, 1000); + applicationStore.clearDynamicTitle(); // Check Token @@ -461,4 +466,14 @@ router.beforeEach(async (to, from, next) => { } }); +router.afterEach((to, from) => { + if (routerLoadingTimeout != null) { + clearTimeout(routerLoadingTimeout); + routerLoadingTimeout = null; + } + + const applicationStore = useApplicationStore(); + applicationStore.setRouterLoading(false); +}); + export default router; diff --git a/resources/js/store/ApplicationStore.ts b/resources/js/store/ApplicationStore.ts index de27ca8..f34114b 100644 --- a/resources/js/store/ApplicationStore.ts +++ b/resources/js/store/ApplicationStore.ts @@ -2,14 +2,14 @@ import { defineStore } from "pinia"; export interface ApplicationStore { dynamicTitle: string; - racers: boolean; + routerLoading: boolean; } export const useApplicationStore = defineStore({ id: "application", state: (): ApplicationStore => ({ dynamicTitle: "", - racers: false, + routerLoading: false, }), actions: { @@ -21,5 +21,9 @@ export const useApplicationStore = defineStore({ clearDynamicTitle() { this.$state.dynamicTitle = ""; }, + + setRouterLoading(loading: boolean) { + this.$state.routerLoading = loading; + }, }, }); diff --git a/resources/js/views/App.vue b/resources/js/views/App.vue index b4c0414..a264bcf 100644 --- a/resources/js/views/App.vue +++ b/resources/js/views/App.vue @@ -8,13 +8,18 @@ +