30 lines
646 B
TypeScript
30 lines
646 B
TypeScript
import type {IList} from '@/modelTypes/IList'
|
|
|
|
const key = 'collapsedBuckets'
|
|
|
|
function getAllState() {
|
|
const saved = localStorage.getItem(key)
|
|
return saved === null
|
|
? {}
|
|
: JSON.parse(saved)
|
|
}
|
|
|
|
export function saveCollapsedBucketState(
|
|
listId: IList['id'],
|
|
collapsedBuckets: any,
|
|
) {
|
|
const state = getAllState()
|
|
state[listId] = collapsedBuckets
|
|
for (const bucketId in state[listId]) {
|
|
if (!state[listId][bucketId]) {
|
|
delete state[listId][bucketId]
|
|
}
|
|
}
|
|
localStorage.setItem(key, JSON.stringify(state))
|
|
}
|
|
|
|
export function getCollapsedBucketState(listId: IList['id']) {
|
|
const state = getAllState()
|
|
return state[listId] ?? {}
|
|
}
|