Files
cinny/src/app/state/closedNavCategories.ts
T
Lotus Bot 22328231bd
CI / Build & Quality Checks (push) Successful in 10m5s
chore: bulk dependency updates + fix immer v11 default import + sentry test
Package updates (safe minor/major bumps, all build-verified):
- @tanstack/react-query 5.24->5.100, react-virtual 3.2->3.13
- jotai 2.6->2.20, immer 9->11, dayjs, chroma-js, classnames, blurhash
- slate/slate-dom/slate-react 0.123->0.124
- focus-trap-react 10->12, react-error-boundary 4->6
- html-dom-parser 4->7, html-react-parser 4->6
- pdfjs-dist 4->5, ua-parser-js 1->2
- i18next-http-backend 3->4, i18next-browser-languagedetector 8.0->8.2
- react-aria 3.29->3.48, matrix-widget-api 1.16->1.17
- @atlaskit/pragmatic-drag-and-drop* minor bumps
- @rollup/plugin-inject 5.0.3->5.0.5, @rollup/plugin-wasm 6.1->6.2
- @element-hq/element-call-embedded 0.19.3->0.19.4
- @types/* patches, eslint-plugin-* minors

Breaking change fix:
- immer v11 removed default export; updated 11 files to named import

Temporary: add Sentry test button to WelcomePage for verification.
Remove after confirming errors reach the dashboard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 22:23:19 -04:00

69 lines
1.7 KiB
TypeScript

import { WritableAtom, atom } from 'jotai';
import { produce } from 'immer';
import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';
const CLOSED_NAV_CATEGORY = 'closedNavCategories';
type ClosedNavCategoriesAction =
| {
type: 'PUT';
categoryId: string;
}
| {
type: 'DELETE';
categoryId: string;
};
export type ClosedNavCategoriesAtom = WritableAtom<
Set<string>,
[ClosedNavCategoriesAction],
undefined
>;
export const makeClosedNavCategoriesAtom = (userId: string): ClosedNavCategoriesAtom => {
const storeKey = `${CLOSED_NAV_CATEGORY}${userId}`;
const baseClosedNavCategoriesAtom = atomWithLocalStorage<Set<string>>(
storeKey,
(key) => {
const arrayValue = getLocalStorageItem<string[]>(key, []);
return new Set(arrayValue);
},
(key, value) => {
const arrayValue = Array.from(value);
setLocalStorageItem(key, arrayValue);
}
);
const closedNavCategoriesAtom = atom<Set<string>, [ClosedNavCategoriesAction], undefined>(
(get) => get(baseClosedNavCategoriesAtom),
(get, set, action) => {
if (action.type === 'DELETE') {
set(
baseClosedNavCategoriesAtom,
produce(get(baseClosedNavCategoriesAtom), (draft) => {
draft.delete(action.categoryId);
})
);
return;
}
if (action.type === 'PUT') {
set(
baseClosedNavCategoriesAtom,
produce(get(baseClosedNavCategoriesAtom), (draft) => {
draft.add(action.categoryId);
})
);
}
}
);
return closedNavCategoriesAtom;
};
export const makeNavCategoryId = (...args: string[]): string => args.join('|');