From 2c0ab5e15a58735924b5e588f2653f394aa8d94f Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Thu, 29 Aug 2024 14:17:57 +0200 Subject: [PATCH] add update notification to sidebar, fix aborted requests on navigate --- .../Components/UpdateSidebarNotification.vue | 46 +++++++++++++++++++ resources/js/Layouts/AppLayout.vue | 34 +++++++++----- 2 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 resources/js/Components/UpdateSidebarNotification.vue diff --git a/resources/js/Components/UpdateSidebarNotification.vue b/resources/js/Components/UpdateSidebarNotification.vue new file mode 100644 index 00000000..e968ff21 --- /dev/null +++ b/resources/js/Components/UpdateSidebarNotification.vue @@ -0,0 +1,46 @@ + + + + + diff --git a/resources/js/Layouts/AppLayout.vue b/resources/js/Layouts/AppLayout.vue index 23064f8d..ca3427b2 100644 --- a/resources/js/Layouts/AppLayout.vue +++ b/resources/js/Layouts/AppLayout.vue @@ -33,24 +33,33 @@ import { isBillingActivated } from '@/utils/billing'; import type { User } from '@/types/models'; import { ArrowsRightLeftIcon } from '@heroicons/vue/16/solid'; import { fetchToken, isTokenValid } from '@/utils/session'; +import UpdateSidebarNotification from '@/Components/UpdateSidebarNotification.vue'; defineProps({ title: String, }); const showSidebarMenu = ref(false); - +const isUnloading = ref(false); onMounted(async () => { // make sure that the initial requests are only loaded once, this can be removed once we move away from inertia if (window.initialDataLoaded !== true) { window.initialDataLoaded = true; initializeStores(); } + window.onbeforeunload = () => { + isUnloading.value = true; + }; window.onfocus = async () => { if (!isTokenValid()) { await fetchToken(); } - refreshStores(); + setTimeout(() => { + // prevent store refreshing on navigation + if (isUnloading.value === false) { + refreshStores(); + } + }, 100); }; }); @@ -178,16 +187,19 @@ const page = usePage<{ - +