feat: enhance sidebar navigation with localStorage state management and section key support
This commit is contained in:
@@ -2,6 +2,8 @@ export type DashboardNavActiveItem = {
|
||||
url: string
|
||||
}
|
||||
|
||||
const DASHBOARD_NAV_SECTION_STORAGE_PREFIX = "dashboard.sidebar.navSection"
|
||||
|
||||
function normalizePath(path: string) {
|
||||
return path !== "/" ? path.replace(/\/+$/, "") : path
|
||||
}
|
||||
@@ -22,3 +24,17 @@ export function dashboardNavSectionHasActiveItem(
|
||||
) {
|
||||
return items.some((item) => isDashboardNavItemActive(pathname, item.url))
|
||||
}
|
||||
|
||||
export function getDashboardNavSectionStorageKey(sectionKey: string) {
|
||||
return `${DASHBOARD_NAV_SECTION_STORAGE_PREFIX}.${sectionKey}.open`
|
||||
}
|
||||
|
||||
export function parseDashboardNavSectionOpenState(value: string | null) {
|
||||
if (value === "true") {
|
||||
return true
|
||||
}
|
||||
if (value === "false") {
|
||||
return false
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user