fix: restore current page after refresh
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user