From ab9968f75b65974cd7fab9c12689039300d7c379 Mon Sep 17 00:00:00 2001 From: Richard R Date: Thu, 19 Mar 2026 12:35:01 -0600 Subject: [PATCH] feat(config): implement reset logic for TTS provider settings based on feature flag --- src/contexts/ConfigContext.tsx | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/contexts/ConfigContext.tsx b/src/contexts/ConfigContext.tsx index 70b8a18..f91c8e6 100644 --- a/src/contexts/ConfigContext.tsx +++ b/src/contexts/ConfigContext.tsx @@ -53,6 +53,7 @@ const ConfigContext = createContext(undefined); export function ConfigProvider({ children }: { children: ReactNode }) { const [isLoading, setIsLoading] = useState(true); const [isDBReady, setIsDBReady] = useState(false); + const ttsProvidersTabDisabled = process.env.NEXT_PUBLIC_ENABLE_TTS_PROVIDERS_TAB === 'false'; const didRunStartupMigrations = useRef(false); const didAttemptInitialPreferenceSeedForSession = useRef(null); const syncedPreferenceKeys = useMemo(() => new Set(SYNCED_PREFERENCE_KEYS), []); @@ -217,6 +218,41 @@ export function ConfigProvider({ children }: { children: ReactNode }) { return { ...APP_CONFIG_DEFAULTS, ...rest }; }, [appConfig]); + useEffect(() => { + if (!ttsProvidersTabDisabled || !isDBReady || !appConfig) return; + + const resetPatch: Partial = {}; + + if (appConfig.apiKey !== APP_CONFIG_DEFAULTS.apiKey) { + resetPatch.apiKey = APP_CONFIG_DEFAULTS.apiKey; + } + if (appConfig.baseUrl !== APP_CONFIG_DEFAULTS.baseUrl) { + resetPatch.baseUrl = APP_CONFIG_DEFAULTS.baseUrl; + } + if (appConfig.ttsProvider !== APP_CONFIG_DEFAULTS.ttsProvider) { + resetPatch.ttsProvider = APP_CONFIG_DEFAULTS.ttsProvider; + } + if (appConfig.ttsModel !== APP_CONFIG_DEFAULTS.ttsModel) { + resetPatch.ttsModel = APP_CONFIG_DEFAULTS.ttsModel; + } + if (appConfig.ttsInstructions !== APP_CONFIG_DEFAULTS.ttsInstructions) { + resetPatch.ttsInstructions = APP_CONFIG_DEFAULTS.ttsInstructions; + } + if (appConfig.voice !== APP_CONFIG_DEFAULTS.voice) { + resetPatch.voice = APP_CONFIG_DEFAULTS.voice; + } + if (Object.keys(appConfig.savedVoices || {}).length > 0) { + resetPatch.savedVoices = APP_CONFIG_DEFAULTS.savedVoices; + } + + if (Object.keys(resetPatch).length === 0) return; + + updateAppConfig(resetPatch).catch((error) => { + console.warn('Failed to clear hidden TTS provider settings:', error); + }); + queueSyncedPreferencePatch(resetPatch); + }, [ttsProvidersTabDisabled, isDBReady, appConfig, queueSyncedPreferencePatch]); + useEffect(() => { if (!isDBReady || !authEnabled || !appConfig || isSessionPending) return; if (didAttemptInitialPreferenceSeedForSession.current === sessionKey) return;