diff options
Diffstat (limited to 'src/state/persisted/store.ts')
-rw-r--r-- | src/state/persisted/store.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/state/persisted/store.ts b/src/state/persisted/store.ts new file mode 100644 index 000000000..2b03bec20 --- /dev/null +++ b/src/state/persisted/store.ts @@ -0,0 +1,18 @@ +import AsyncStorage from '@react-native-async-storage/async-storage' + +import {Schema, schema} from '#/state/persisted/schema' + +const BSKY_STORAGE = 'BSKY_STORAGE' + +export async function write(value: Schema) { + schema.parse(value) + await AsyncStorage.setItem(BSKY_STORAGE, JSON.stringify(value)) +} + +export async function read(): Promise<Schema | undefined> { + const rawData = await AsyncStorage.getItem(BSKY_STORAGE) + const objData = rawData ? JSON.parse(rawData) : undefined + if (schema.safeParse(objData).success) { + return objData + } +} |