diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index 1e6837b0..f0975f6e 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -15,13 +15,13 @@ interface AppProviderProps { } // Zod schema for AppConfig validation -const AppConfigSchema: z.ZodType = z.object({ +const AppConfigSchema = z.object({ theme: z.enum(['dark', 'light', 'system']), relayUrl: z.string().url(), deployServer: z.string().min(1), esmUrl: z.string().url(), - language: z.string().optional(), -}); + language: z.string(), +}) satisfies z.ZodType; export function AppProvider(props: AppProviderProps) { const { @@ -32,23 +32,25 @@ export function AppProvider(props: AppProviderProps) { } = props; // App configuration state with localStorage persistence - const [config, setConfig] = useLocalStorage( + const [rawConfig, setConfig] = useLocalStorage>( storageKey, - defaultConfig, + {}, { serialize: JSON.stringify, deserialize: (value: string) => { const parsed = JSON.parse(value); - return AppConfigSchema.parse(parsed); + return AppConfigSchema.partial().parse(parsed); } } ); // Generic config updater with callback pattern - const updateConfig = (updater: (currentConfig: AppConfig) => AppConfig) => { + const updateConfig = (updater: (currentConfig: Partial) => Partial) => { setConfig(updater); }; + const config = { ...defaultConfig, ...rawConfig }; + const appContextValue: AppContextType = { config, updateConfig, diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index 11e037fa..093319ff 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -19,7 +19,7 @@ export interface AppContextType { /** Current application configuration */ config: AppConfig; /** Update configuration using a callback that receives current config and returns new config */ - updateConfig: (updater: (currentConfig: AppConfig) => AppConfig) => void; + updateConfig: (updater: (currentConfig: Partial) => Partial) => void; /** Optional list of preset relays to display in the RelaySelector */ presetRelays?: { name: string; url: string }[]; }