Add About screen, list of recently opened vaults, category filtering
This commit is contained in:
@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react"
|
||||
|
||||
export enum Key {
|
||||
LAST_VAULT_PATH = "app.state.last_vault_path",
|
||||
RECENTLY_OPENED_VAULTS = "app.state.recently_opened_vaults",
|
||||
PREFERRED_LOCALE = "app.config.locale",
|
||||
ENABLE_AUTO_LOCK = "app.config.enable_auto_lock",
|
||||
AUTO_LOCK_AFTER = "app.config.auto_lock_after",
|
||||
@ -9,6 +10,7 @@ export enum Key {
|
||||
|
||||
interface StoredData {
|
||||
[Key.LAST_VAULT_PATH]: string
|
||||
[Key.RECENTLY_OPENED_VAULTS]: string[]
|
||||
[Key.PREFERRED_LOCALE]: string
|
||||
[Key.ENABLE_AUTO_LOCK]: boolean
|
||||
[Key.AUTO_LOCK_AFTER]: number
|
||||
@ -27,7 +29,7 @@ export function useStorage<K extends Key>(key: K) {
|
||||
}
|
||||
}, [key])
|
||||
const setState2 = useCallback(
|
||||
(value: StoredData[K]) => {
|
||||
(value: ((value: StoredData[K]) => StoredData[K]) | StoredData[K]) => {
|
||||
set(key, value)
|
||||
},
|
||||
[key]
|
||||
@ -43,10 +45,16 @@ export function get<K extends Key>(key: K): StoredData[K] | undefined {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function set<K extends Key>(key: K, value: StoredData[K]) {
|
||||
export function set<K extends Key>(
|
||||
key: K,
|
||||
value: ((value: StoredData[K]) => StoredData[K]) | StoredData[K]
|
||||
) {
|
||||
try {
|
||||
if (typeof value === "function") {
|
||||
value = value(get(key)!)
|
||||
}
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
events.get(key).forEach(fn => fn(value))
|
||||
events.get(key).forEach(fn => fn(value as StoredData[K]))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
@ -64,4 +72,5 @@ const defaults: typeof set = (key, value) => {
|
||||
}
|
||||
}
|
||||
defaults(Key.ENABLE_AUTO_LOCK, true)
|
||||
defaults(Key.AUTO_LOCK_AFTER, 120)
|
||||
defaults(Key.AUTO_LOCK_AFTER, 180)
|
||||
defaults(Key.RECENTLY_OPENED_VAULTS, [])
|
||||
|
Reference in New Issue
Block a user