forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSidebarPreferences.ts
More file actions
55 lines (50 loc) · 1.81 KB
/
useSidebarPreferences.ts
File metadata and controls
55 lines (50 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// src/hooks/useSidebarPreferences.ts
"use client"
import { useLocalStorage } from "@/hooks/useLocalStorage"
import type { SortMode } from "@/hooks/useTrackerList"
import type { StatMode } from "@/lib/formatters"
import { STORAGE_KEYS } from "@/lib/storage-keys"
interface UseSidebarPreferencesReturn {
statMode: StatMode
setStatMode: (mode: StatMode) => void
sortMode: SortMode
setSortMode: (mode: SortMode) => void
filtersExpanded: boolean
setFiltersExpanded: (value: boolean | ((prev: boolean) => boolean)) => void
showFavoritesOnly: boolean
setShowFavoritesOnly: (value: boolean | ((prev: boolean) => boolean)) => void
showArchived: boolean
setShowArchived: (value: boolean | ((prev: boolean) => boolean)) => void
unlocked: boolean
setUnlocked: (value: boolean | ((prev: boolean) => boolean)) => void
}
function useSidebarPreferences(): UseSidebarPreferencesReturn {
const [statMode, setStatMode] = useLocalStorage<StatMode>(STORAGE_KEYS.SIDEBAR_STAT_MODE, "ratio")
const [sortMode, setSortMode] = useLocalStorage<SortMode>(STORAGE_KEYS.SIDEBAR_SORT_MODE, "index")
const [filtersExpanded, setFiltersExpanded] = useLocalStorage(
STORAGE_KEYS.SIDEBAR_FILTERS_EXPANDED,
true
)
const [showFavoritesOnly, setShowFavoritesOnly] = useLocalStorage(
STORAGE_KEYS.SIDEBAR_FAVORITES_ONLY,
false
)
const [showArchived, setShowArchived] = useLocalStorage(STORAGE_KEYS.SIDEBAR_SHOW_ARCHIVED, false)
const [unlocked, setUnlocked] = useLocalStorage(STORAGE_KEYS.SIDEBAR_UNLOCKED, false)
return {
statMode,
setStatMode,
sortMode,
setSortMode,
filtersExpanded,
setFiltersExpanded,
showFavoritesOnly,
setShowFavoritesOnly,
showArchived,
setShowArchived,
unlocked,
setUnlocked,
}
}
export type { UseSidebarPreferencesReturn }
export { useSidebarPreferences }