Add resetSidebar() to useSidebar composable and call it on logout to prevent stale sidebar data after re-login. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import type { SidebarSection } from '~/shared/types'
|
|
|
|
const sections = ref<SidebarSection[]>([])
|
|
const disabledRoutes = ref<string[]>([])
|
|
const loaded = ref(false)
|
|
|
|
export function useSidebar() {
|
|
async function loadSidebar() {
|
|
try {
|
|
const api = useApi()
|
|
const data = await api.get<{ sections: SidebarSection[]; disabledRoutes: string[] }>(
|
|
'/sidebar',
|
|
{},
|
|
{ toast: false }
|
|
)
|
|
sections.value = data.sections ?? []
|
|
disabledRoutes.value = data.disabledRoutes ?? []
|
|
loaded.value = true
|
|
} catch {
|
|
sections.value = []
|
|
disabledRoutes.value = []
|
|
loaded.value = true
|
|
}
|
|
}
|
|
|
|
function isRouteDisabled(path: string): boolean {
|
|
return disabledRoutes.value.some(
|
|
disabled => path === disabled || path.startsWith(disabled + '/')
|
|
)
|
|
}
|
|
|
|
function resetSidebar() {
|
|
sections.value = []
|
|
disabledRoutes.value = []
|
|
loaded.value = false
|
|
}
|
|
|
|
return {
|
|
sections,
|
|
disabledRoutes,
|
|
loaded,
|
|
loadSidebar,
|
|
resetSidebar,
|
|
isRouteDisabled,
|
|
}
|
|
}
|