From fdf055ae222ac2063fa87759479018248657fd63 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 26 Aug 2024 21:33:01 +0300 Subject: feature(mobile): Allow configuring uploaded image quality in the mobile app --- apps/mobile/lib/settings.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'apps/mobile/lib') 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; interface AppSettingsState { settings: { isLoading: boolean; settings: Settings }; @@ -18,7 +22,7 @@ interface AppSettingsState { const useSettings = create((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((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 } })); }, })); -- cgit v1.2.3-70-g09d2