Skip to content

Commit d68c341

Browse files
committed
fix: streamline layout handling in App.vue by replacing mutable refs with computed properties for better clarity and performance
1 parent 607cea4 commit d68c341

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

adminforth/spa/src/App.vue

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ initFrontedAPI()
182182
183183
createHead()
184184
const sideBarOpen = ref(false);
185-
const defaultLayout = ref(true);
186-
const headerOnlyLayout = ref(false);
187185
const route = useRoute();
188186
const router = useRouter();
189187
const publicConfigLoaded = ref(false);
@@ -197,6 +195,14 @@ const isSidebarIconOnly = ref(localStorage.getItem('afIconOnlySidebar') === 'tru
197195
198196
const loggedIn = computed(() => !!coreStore?.adminUser);
199197
198+
const defaultLayout = computed(() => {
199+
return route.meta?.sidebarAndHeader !== 'none';
200+
});
201+
202+
const headerOnlyLayout = computed(() => {
203+
return route.meta?.sidebarAndHeader === 'headerOnly';
204+
});
205+
200206
const expandedWidth = computed(() => coreStore.config?.iconOnlySidebar?.expandedSidebarWidth || '16.5rem');
201207
202208
const theme = ref('light');
@@ -308,19 +314,6 @@ async function loadMenu() {
308314
loginRedirectCheckIsReady.value = true;
309315
}
310316
311-
function handleCustomLayout() {
312-
if (route.meta?.sidebarAndHeader === 'none') {
313-
defaultLayout.value = false;
314-
} else if (route.meta?.sidebarAndHeader === 'preferIconOnly') {
315-
defaultLayout.value = true;
316-
isSidebarIconOnly.value = true;
317-
} else if (route.meta?.sidebarAndHeader === 'headerOnly') {
318-
headerOnlyLayout.value = true;
319-
} else {
320-
defaultLayout.value = true;
321-
}
322-
}
323-
324317
function humanizeSnake(str: string): string {
325318
if (!str) {
326319
return '';
@@ -345,10 +338,11 @@ watch(title, (title) => {
345338
document.title = title;
346339
})
347340
348-
watch([route, () => coreStore.resourceById, () => coreStore.config], async () => {
349-
handleCustomLayout()
350-
await new Promise((resolve) => setTimeout(resolve, 0));
351-
341+
watch(route, () => {
342+
// Handle preferIconOnly layout
343+
if (route.meta?.sidebarAndHeader === 'preferIconOnly') {
344+
isSidebarIconOnly.value = true;
345+
}
352346
});
353347
354348
@@ -376,7 +370,6 @@ onMounted(async () => {
376370
loadPublicConfig(); // and this
377371
// before init flowbite we have to wait router initialized because it affects dom(our v-ifs) and fetch menu
378372
await initRouter();
379-
handleCustomLayout();
380373
381374
adminforth.menu.refreshMenuBadges = async () => {
382375
await coreStore.fetchMenuBadges();

0 commit comments

Comments
 (0)