From 16837284fb18e564fe064d2f5d6b83b1db628de1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 16 Oct 2025 18:33:24 -0500 Subject: [PATCH] Only set app config that's actually changed --- src/components/AppProvider.tsx | 14 ++++++++------ src/contexts/AppContext.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index 79c9e69..5d927b6 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -14,10 +14,10 @@ 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(), -}); +}) satisfies z.ZodType; export function AppProvider(props: AppProviderProps) { const { @@ -28,23 +28,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 e6cfa26..b251202 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -13,7 +13,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 }[]; }