Migrate to native Node.js file access and improve UI
This commit is contained in:
26
packages/web/src/utils/localStorage.ts
Normal file
26
packages/web/src/utils/localStorage.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export const enum Key {
|
||||
LAST_VAULT_PATH = "lastVaultPath",
|
||||
}
|
||||
|
||||
interface StoredData {
|
||||
[Key.LAST_VAULT_PATH]: string
|
||||
}
|
||||
|
||||
export function get<K extends keyof StoredData>(key: K) {
|
||||
try {
|
||||
const value = localStorage.getItem(key)
|
||||
return value == null ? undefined : (JSON.parse(value!) as StoredData[K])
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function set<K extends keyof StoredData>(key: K, value: StoredData[K]) {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function remove(key: keyof StoredData) {
|
||||
try {
|
||||
localStorage.removeItem(key)
|
||||
} catch {}
|
||||
}
|
Reference in New Issue
Block a user