From 706f0cb1859b9d14de139789bb7d9974855bd6fb Mon Sep 17 00:00:00 2001 From: Lance Chant <13349722+lancechant@users.noreply.github.com> Date: Mon, 1 Jun 2026 09:49:21 +0200 Subject: [PATCH] fix: pr comments Allowed the user settings to be saved incase admin unlocks settings Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com> --- .../settings/plugins/streamystats/page.tsx | 2 +- utils/atoms/settings.ts | 79 +++++++------------ 2 files changed, 30 insertions(+), 51 deletions(-) diff --git a/app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx b/app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx index 1c4dcd199..8f0a2c931 100644 --- a/app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx +++ b/app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx @@ -114,7 +114,7 @@ export default function StreamystatsPage() { }; const handleRefreshFromServer = useCallback(async () => { - const newPluginSettings = await refreshStreamyfinPluginSettings(true); + const newPluginSettings = await refreshStreamyfinPluginSettings(); // Update local state with new values const newUrl = newPluginSettings?.streamyStatsServerUrl?.value || ""; setUrl(newUrl); diff --git a/utils/atoms/settings.ts b/utils/atoms/settings.ts index d1c49b022..f4c6c7dd1 100644 --- a/utils/atoms/settings.ts +++ b/utils/atoms/settings.ts @@ -468,58 +468,37 @@ export const useSettings = () => { [_setPluginSettings], ); - const refreshStreamyfinPluginSettings = useCallback( - async (_forceOverride = false) => { - if (!api) { - return; + const refreshStreamyfinPluginSettings = useCallback(async () => { + if (!api) { + return; + } + const newPluginSettings = await api.getStreamyfinPluginConfig().then( + ({ data }) => { + writeInfoLog("Got plugin settings", data?.settings); + return data?.settings; + }, + (_err) => undefined, + ); + setPluginSettings(newPluginSettings); + + // Locked/unlocked values are handled by the settings memo, which + // applies locked values at runtime without overwriting user storage. + // We only handle auto-enabling Streamystats here. + if (newPluginSettings && _settings) { + const streamyStatsUrl = newPluginSettings.streamyStatsServerUrl; + if (streamyStatsUrl?.value && _settings.searchEngine !== "Streamystats") { + const newSettings = { + ...defaultValues, + ..._settings, + searchEngine: "Streamystats", + } as Settings; + setSettings(newSettings); + saveSettings(newSettings); } - const newPluginSettings = await api.getStreamyfinPluginConfig().then( - ({ data }) => { - writeInfoLog("Got plugin settings", data?.settings); - return data?.settings; - }, - (_err) => undefined, - ); - setPluginSettings(newPluginSettings); + } - // Apply locked plugin values to settings (unlocked values are handled - // by the settings memo, which respects user customizations) - if (newPluginSettings && _settings) { - const updates: Partial = {}; - for (const [key, setting] of Object.entries(newPluginSettings)) { - if (setting?.locked) { - const settingsKey = key as keyof Settings; - // Normalize and apply locked values unconditionally - (updates as any)[settingsKey] = normalizePluginValue( - settingsKey, - setting.value, - ); - } - } - - // Auto-enable Streamystats if server URL is provided - const streamyStatsUrl = newPluginSettings.streamyStatsServerUrl; - if ( - streamyStatsUrl?.value && - _settings.searchEngine !== "Streamystats" - ) { - updates.searchEngine = "Streamystats"; - } - if (Object.keys(updates).length > 0) { - const newSettings = { - ...defaultValues, - ..._settings, - ...updates, - } as Settings; - setSettings(newSettings); - saveSettings(newSettings); - } - } - - return newPluginSettings; - }, - [api, _settings], - ); + return newPluginSettings; + }, [api, _settings]); const updateSettings = (update: Partial) => { if (!_settings) {