Skip to content

Commit fd4eddb

Browse files
committed
fix: improve ulr change handling for SettingsView
1 parent b5e65ee commit fd4eddb

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

adminforth/spa/src/components/UserMenuSettingsButton.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const showDropdown = ref(false);
5050
const props = defineProps(['meta', 'resource']);
5151
5252
const options = computed(() => {
53-
console.log('Returning setting pages', coreStore.config?.settingPages);
5453
return coreStore.config?.settingPages?.map((page) => {
5554
return {
5655
pageLabel: page.pageLabel,
@@ -69,13 +68,10 @@ function slugifyString(str: string): string {
6968
}
7069
7170
function navigateTo(option: { slug?: string | null | undefined, pageLabel: string }) {
72-
console.log('Navigating to option', option);
7371
if (option.slug) {
74-
console.log('Navigating to settings page', option.slug);
75-
router.push({ name: 'settings', query: { page: option.slug } });
72+
router.push({ name: 'settings', params: { page: option.slug } });
7673
} else {
7774
const destinationSlug = slugifyString(option.pageLabel);
78-
console.log('Navigating to settings page by label', destinationSlug);
7975
router.push({ name: 'settings', params: { page: destinationSlug } });
8076
}
8177
}

adminforth/spa/src/views/SettingsView.vue

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<div v-if="!coreStore?.config?.settingPages || coreStore?.config?.settingPages.length === 0">
6969
<p>No setting pages configured or still loading...</p>
7070
</div>
71-
<VerticalTabs v-else ref="VerticalTabsRef" @update:active-tab="setURL({slug: $event, pageLabel: ''})">
71+
<VerticalTabs v-else ref="VerticalTabsRef" v-model:active-tab="activeTab" @update:active-tab="setURL({slug: $event, pageLabel: ''})">
7272
<template v-for="(c,i) in coreStore?.config?.settingPages" :key="`tab:${settingPageSlotName(c,i)}`" v-slot:['tab:'+settingPageSlotName(c,i)]>
7373
<div class="flex items-center justify-center whitespace-nowrap w-full px-4 gap-2" @click="setURL(c)">
7474
<component v-if="c.icon" :is="getIcon(c.icon)" class="w-5 h-5 group-hover:text-lightSidebarIconsHover transition duration-75 dark:group-hover:text-darkSidebarIconsHover dark:text-darkSidebarIcons" ></component>
@@ -98,6 +98,7 @@ import { IconMoonSolid, IconSunSolid } from '@iconify-prerendered/vue-flowbite';
9898
import adminforth from '@/adminforth';
9999
import { VerticalTabs } from '@/afcl'
100100
import { useRoute } from 'vue-router'
101+
import UserMenuSettingsButton from '../components/UserMenuSettingsButton.vue';
101102
102103
const route = useRoute()
103104
const coreStore = useCoreStore();
@@ -111,6 +112,11 @@ const sideBarOpen = ref(false);
111112
const theme = ref('light');
112113
const dropdownUserButton = ref<HTMLElement | null>(null);
113114
const VerticalTabsRef = ref();
115+
const activeTab = ref('');
116+
117+
watch(() => route?.params?.page, (val) => {
118+
handleURLChange(val as string | null);
119+
});
114120
115121
async function initRouter() {
116122
await router.isReady();
@@ -157,20 +163,7 @@ onMounted(async () => {
157163
setURL(coreStore.config.settingPages[0]);
158164
}
159165
} else {
160-
let isParamInTabs;
161-
for (const c of coreStore?.config?.settingPages || []) {
162-
if (c.slug ? c.slug === routeParamsPage : slugifyString(c.pageLabel) === routeParamsPage) {
163-
isParamInTabs = true;
164-
break;
165-
}
166-
}
167-
if (isParamInTabs) {
168-
VerticalTabsRef.value.setActiveTab(routeParamsPage);
169-
} else {
170-
if (coreStore.config?.settingPages?.[0]) {
171-
setURL(coreStore.config.settingPages[0]);
172-
}
173-
}
166+
handleURLChange(routeParamsPage as string | null);
174167
}
175168
});
176169
@@ -205,4 +198,22 @@ function setURL(item: {
205198
});
206199
}
207200
}
201+
202+
function handleURLChange(val: string | null) {
203+
let isParamInTabs;
204+
for (const c of coreStore?.config?.settingPages || []) {
205+
if (c.slug ? c.slug === val : slugifyString(c.pageLabel) === val) {
206+
isParamInTabs = true;
207+
break;
208+
}
209+
}
210+
if (isParamInTabs) {
211+
VerticalTabsRef.value.setActiveTab(val);
212+
activeTab.value = val as string;
213+
} else {
214+
if (coreStore.config?.settingPages?.[0]) {
215+
setURL(coreStore.config.settingPages[0]);
216+
}
217+
}
218+
}
208219
</script>

0 commit comments

Comments
 (0)