diff options
| author | MohamedBassem <me@mbassem.com> | 2024-08-26 21:33:01 +0300 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-08-26 21:33:01 +0300 |
| commit | fdf055ae222ac2063fa87759479018248657fd63 (patch) | |
| tree | 686d5d921ae42f9108dbfa9faf00a9d10006f94f /apps/mobile/lib/settings.ts | |
| parent | 140554021e83ca375845584f8d7e5e476434f1c0 (diff) | |
| download | karakeep-fdf055ae222ac2063fa87759479018248657fd63.tar.zst | |
feature(mobile): Allow configuring uploaded image quality in the mobile app
Diffstat (limited to 'apps/mobile/lib/settings.ts')
| -rw-r--r-- | apps/mobile/lib/settings.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/apps/mobile/lib/settings.ts b/apps/mobile/lib/settings.ts index efb5593a..085f4f01 100644 --- a/apps/mobile/lib/settings.ts +++ b/apps/mobile/lib/settings.ts @@ -1,13 +1,17 @@ import * as SecureStore from "expo-secure-store"; +import { z } from "zod"; import { create } from "zustand"; const SETTING_NAME = "settings"; -export interface Settings { - apiKey?: string; - apiKeyId?: string; - address: string; -} +const zSettingsSchema = z.object({ + apiKey: z.string().optional(), + apiKeyId: z.string().optional(), + address: z.string(), + imageQuality: z.number().optional().default(0.2), +}); + +export type Settings = z.infer<typeof zSettingsSchema>; interface AppSettingsState { settings: { isLoading: boolean; settings: Settings }; @@ -18,7 +22,7 @@ interface AppSettingsState { const useSettings = create<AppSettingsState>((set, get) => ({ settings: { isLoading: true, - settings: { address: "" }, + settings: { address: "", imageQuality: 0.2 }, }, setSettings: async (settings) => { await SecureStore.setItemAsync(SETTING_NAME, JSON.stringify(settings)); @@ -36,7 +40,7 @@ const useSettings = create<AppSettingsState>((set, get) => ({ return; } // TODO Wipe the state if invalid - const parsed = JSON.parse(strVal) as Settings; + const parsed = zSettingsSchema.parse(JSON.parse(strVal)); set((_state) => ({ settings: { isLoading: false, settings: parsed } })); }, })); |
