Skip to content

A self-hosted media server and file management system

fix: dashboard tabs breaks page titles on config and settings

aminnausina7f041e35429
diff --git a/resources/js/components/dashboard/DashboardTabs.ts b/resources/js/components/dashboard/DashboardTabs.ts
index ce0776b9..bfac0b4e 100644
--- a/resources/js/components/dashboard/DashboardTabs.ts
+++ b/resources/js/components/dashboard/DashboardTabs.ts
@@ -1,11 +1,8 @@
-import type { SidebarTabItem } from '@/types/types';
-
-import { computed, ref, watch } from 'vue';
import { useDashboardStore } from '@/stores/DashboardStore';
-import { useAuthStore } from '@/stores/AuthStore';
+import { createTabStore } from '@/stores/TabStore';
import { storeToRefs } from 'pinia';
-import { useAppStore } from '@/stores/AppStore';
-import { useRoute } from 'vue-router';
+import { useAuth } from '@/composables/auth/useAuth';
+import { watch } from 'vue';
import ProiconsLibrary from '~icons/proicons/library';
import ProiconsGraph from '~icons/proicons/graph';
@@ -13,15 +10,12 @@ import CircumServer from '~icons/circum/server';
import LucideUsers from '~icons/lucide/users';
export function useDashboardTabs() {
- const { stateTaskStats, stateTotalLibrariesSize, stateLibraryId, stateActiveSessions } = storeToRefs(useDashboardStore());
-
- const { userData } = storeToRefs(useAuthStore());
- const { pageTitle } = storeToRefs(useAppStore());
+ const { stateLibraryId } = storeToRefs(useDashboardStore());
- const route = useRoute();
+ const store = createTabStore('dashboard', () => {
+ const { stateTaskStats, stateTotalLibrariesSize, stateActiveSessions } = storeToRefs(useDashboardStore());
- const dashboardTab = ref<{ name: string; title?: string; icon?: any }>();
- const dashboardTabs = computed<SidebarTabItem[]>(() => {
+ const { userData } = useAuth();
return [
{
name: 'overview',
@@ -55,30 +49,16 @@ export function useDashboardTabs() {
disabled: userData.value?.id !== 1,
},
];
- });
+ })();
- watch(
- () => route?.params?.tab,
- (URL_TAB) => {
- if (!URL_TAB) return;
- const defaultTab = dashboardTabs.value.find((tab) => tab.title === URL_TAB || tab.name === URL_TAB) ?? dashboardTabs.value[0];
-
- pageTitle.value = defaultTab.title ?? defaultTab.name;
- dashboardTab.value = defaultTab;
- },
- { immediate: true },
- );
+ const { tabs, activeTab } = storeToRefs(store);
watch(
- () => dashboardTab.value,
+ () => activeTab.value,
() => {
stateLibraryId.value = -1;
- if (!dashboardTab.value) return;
- pageTitle.value = dashboardTab.value.title ?? dashboardTab.value.name;
},
);
- return {
- dashboardTabs,
- activeDashboardTab: dashboardTab,
- };
+
+ return { dashboardTabs: tabs, activeDashboardTab: activeTab, setTab: store.setTab };
}
diff --git a/resources/js/views/DashboardView.vue b/resources/js/views/DashboardView.vue
index f1b79fe4..bb42f23c 100644
--- a/resources/js/views/DashboardView.vue
+++ b/resources/js/views/DashboardView.vue
@@ -1,16 +1,19 @@
<script setup lang="ts">
-import { computed, defineAsyncComponent, onMounted } from 'vue';
+import { computed, defineAsyncComponent, onMounted, watch } from 'vue';
import { useDashboardTabs } from '@/components/dashboard/DashboardTabs';
import { getScreenSize } from '@/service/util';
import { useAppStore } from '@/stores/AppStore';
+import { useRoute } from 'vue-router';
import DashboardSkeleton from '@/components/dashboard/DashboardSkeleton.vue';
import DashboardSidebar from '@/components/panels/DashboardSidebar.vue';
import LayoutBase from '@/layouts/LayoutBase.vue';
-const { activeDashboardTab } = useDashboardTabs();
+const { activeDashboardTab, setTab } = useDashboardTabs();
const { cycleSideBar } = useAppStore();
+const route = useRoute();
+
const DashboardAnalytics = defineAsyncComponent(() => import('@/components/dashboard/DashboardAnalytics.vue'));
const DashboardLibraries = defineAsyncComponent(() => import('@/components/dashboard/DashboardLibraries.vue'));
const DashboardActivity = defineAsyncComponent(() => import('@/components/dashboard/DashboardActivity.vue'));
@@ -41,6 +44,8 @@ onMounted(async () => {
cycleSideBar('dashboard', 'left-card', false);
});
+
+watch(() => route.params.tab, setTab, { immediate: true });
</script>
<template>