fix: restore current page after refresh
ci / gitleaks (push) Successful in 7s
ci / docker (push) Successful in 3m28s

This commit is contained in:
2026-09-08 12:50:36 +08:00
parent 798725ad29
commit 61f8c27e6c
4 changed files with 62 additions and 9 deletions
+17
View File
@@ -1,4 +1,21 @@
type BooleanStorage = Pick<Storage, 'getItem' | 'setItem'>
type NavigationView = 'tasks' | 'today' | 'upcoming' | 'trash' | 'habits' | 'countdowns' | 'settings'
type StoredNavigation = { view: NavigationView; listId: string }
const NAVIGATION_VIEWS = new Set<NavigationView>(['tasks', 'today', 'upcoming', 'trash', 'habits', 'countdowns', 'settings'])
export function readStoredNavigation(storage: BooleanStorage, key: string): StoredNavigation {
try {
const value = JSON.parse(storage.getItem(key) ?? 'null')
if (value && NAVIGATION_VIEWS.has(value.view) && typeof value.listId === 'string') {
return { view: value.view, listId: value.listId }
}
} catch { /* storage may be unavailable or invalid */ }
return { view: defaultView(), listId: '' }
}
export function writeStoredNavigation(storage: BooleanStorage, key: string, view: NavigationView, listId: string) {
try { storage.setItem(key, JSON.stringify({ view, listId })) } catch { /* storage may be unavailable */ }
}
export function readStoredBoolean(storage: BooleanStorage, key: string, fallback: boolean) {
try {