This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/saveCollapsedBucketState.ts

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] ?? {}
}