44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { createStorageHook } from "@kri/common/hooks";
|
|
import {
|
|
getLocalStorage,
|
|
getSessionStorage,
|
|
removeLocalStorage,
|
|
removeSessionStorage,
|
|
setLocalStorage,
|
|
setSessionStorage,
|
|
} from "@/store/storage/secure-storage";
|
|
import { StorageKeys, StorageType } from "@/store/storage/storage-keys";
|
|
import type { AuthState } from "@/hooks/useAuth";
|
|
import type { SelectedProject } from "@/store/jotai/project";
|
|
import type { ItrntUserInfo } from "@/types/user";
|
|
import type { LastListVisit } from "@/types/list";
|
|
|
|
type ContactStorageSchema = {
|
|
[StorageKeys.AuthState]: AuthState;
|
|
[StorageKeys.SelectedProject]: SelectedProject;
|
|
[StorageKeys.ItrntUserList]: ItrntUserInfo[];
|
|
[StorageKeys.LastListVisit]: LastListVisit;
|
|
};
|
|
|
|
type ContactStorageKey = Extract<keyof ContactStorageSchema, string>;
|
|
|
|
const useCommonStorage = createStorageHook<ContactStorageSchema>({
|
|
resolveStorageScope: (key) => StorageType[key],
|
|
localStorageAdapter: {
|
|
get: getLocalStorage,
|
|
set: setLocalStorage,
|
|
remove: removeLocalStorage,
|
|
},
|
|
sessionStorageAdapter: {
|
|
get: getSessionStorage,
|
|
set: setSessionStorage,
|
|
remove: removeSessionStorage,
|
|
},
|
|
});
|
|
|
|
export const useStorage = <TKey extends ContactStorageKey>(key: TKey) => {
|
|
return useCommonStorage(key);
|
|
};
|