-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathstores.ts
39 lines (34 loc) · 1.21 KB
/
stores.ts
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
import { writable } from 'svelte/store'
import type { ItemId } from '$shared/types'
function createPersistedStore<T>(key: string, startValue: T) {
const { subscribe, set } = writable(startValue)
return {
subscribe,
set,
useLocalStorage: () => {
const json = localStorage.getItem(key)
if (typeof json === 'string') {
let data: T
try {
data = JSON.parse(json)
} catch (error) {
data = startValue
}
set(data)
}
subscribe((current) => {
localStorage.setItem(key, JSON.stringify(current))
})
},
}
}
export const selectedSkills = createPersistedStore<ItemId[]>('selectedSkills', [])
export const selectedTags = createPersistedStore<ItemId[]>('selectedTags', [])
export const isMenuOpen = writable<boolean>(false)
export const filtersExpanded = writable<boolean>(false)
export const visibleItems = writable<number>(20)
export const scrollbarWidth = writable<number>(0)
/**
* This store is used to disable scrolling when updating filters.
*/
export const listenForScroll = writable<boolean>(true)