Skip to content

Commit 7123b27

Browse files
committed
use indexdb for storage
1 parent bcea1f1 commit 7123b27

File tree

3 files changed

+77
-51
lines changed

3 files changed

+77
-51
lines changed

apps/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@opendatacapture/schemas": "workspace:*",
2424
"axios": "catalog:",
2525
"esbuild-wasm": "catalog:",
26+
"idb-keyval": "^6.2.2",
2627
"immer": "^10.1.1",
2728
"jszip": "^3.10.1",
2829
"jwt-decode": "^4.0.0",

apps/playground/src/store/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable import/exports-last */
2+
import { del, get, set } from 'idb-keyval';
23
import { jwtDecode } from 'jwt-decode';
34
import { pick } from 'lodash-es';
45
import { create } from 'zustand';
56
import { createJSONStorage, devtools, persist, subscribeWithSelector } from 'zustand/middleware';
7+
import type { StateStorage } from 'zustand/middleware';
68
import { immer } from 'zustand/middleware/immer';
79

810
import { resolveIndexFilename } from '@/utils/file';
@@ -16,6 +18,18 @@ import { createViewerSlice } from './slices/viewer.slice';
1618

1719
import type { AppStore } from './types';
1820

21+
const storage: StateStorage = {
22+
getItem: async (name: string): Promise<null | string> => {
23+
return (await get(name)) ?? null;
24+
},
25+
removeItem: async (name: string): Promise<void> => {
26+
await del(name);
27+
},
28+
setItem: async (name: string, value: string): Promise<void> => {
29+
await set(name, value);
30+
}
31+
};
32+
1933
export const useAppStore = create(
2034
devtools(
2135
persist(
@@ -64,7 +78,7 @@ export const useAppStore = create(
6478
_accessToken: state.auth?.accessToken
6579
};
6680
},
67-
storage: createJSONStorage(() => localStorage),
81+
storage: createJSONStorage(() => storage),
6882
version: 1
6983
}
7084
)

0 commit comments

Comments
 (0)