feature(dashboard): remember last selected range
This commit is contained in:
23
apps/dashboard/src/utils/storage.ts
Normal file
23
apps/dashboard/src/utils/storage.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
const prefix = '@op';
|
||||
|
||||
export function getStorageItem<T>(key: string): T | null;
|
||||
export function getStorageItem<T>(key: string, defaultValue: T): T;
|
||||
export function getStorageItem<T>(key: string, defaultValue?: T): T | null {
|
||||
if (typeof window === 'undefined') return defaultValue ?? null;
|
||||
const item = localStorage.getItem(`${prefix}:${key}`);
|
||||
if (item === null) {
|
||||
return defaultValue ?? null;
|
||||
}
|
||||
|
||||
return item as T;
|
||||
}
|
||||
|
||||
export function setStorageItem(key: string, value: unknown) {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.setItem(`${prefix}:${key}`, value as string);
|
||||
}
|
||||
|
||||
export function removeStorageItem(key: string) {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.removeItem(`${prefix}:${key}`);
|
||||
}
|
||||
Reference in New Issue
Block a user