From 64f9a84678d14575f5b1261bbdf7b365de0055fc Mon Sep 17 00:00:00 2001 From: WonderAliceUwU Date: Tue, 17 Nov 2026 16:29:46 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20turn=20the=20settings=20che?= =?UTF-8?q?ck=20button=20amber=20while=20there=20are=20unsaved=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 39 ++++++++++++++++++++++++++++++++------- src/index.css | 17 +++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 84df672..cd1e699 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -120,6 +120,11 @@ function App() { const [notice, setNotice] = useState('') const [password, setPassword] = useState('') const [config, setConfig] = useState(defaultConfig) + // What the server has, to tell when the settings on screen have unsaved changes. + const savedConfigJson = useRef(JSON.stringify(defaultConfig)) + const configRef = useRef(config) + configRef.current = config + const settingsDirty = JSON.stringify(config) !== savedConfigJson.current const [options, setOptions] = useState({ jellyfinUsers: [], sonarrRootFolders: [], @@ -171,6 +176,11 @@ function App() { setEntryTransitionState('idle') } + function applyServerConfig(next: AppConfig) { + savedConfigJson.current = JSON.stringify(next) + setConfig(next) + } + async function refreshBaseData() { const [settings, serviceOptions, dashboard, storage, savedWishlist] = await Promise.all([ api.getSettings(), @@ -181,7 +191,10 @@ function App() { ]) setWishlist(savedWishlist.items) - setConfig(settings) + // Edits that are not saved yet are not replaced by the periodic refresh. + if (JSON.stringify(configRef.current) === savedConfigJson.current) { + applyServerConfig(settings) + } setOptions(serviceOptions) setDownloads(dashboard.downloads) setProcessingItems(dashboard.processing || []) @@ -374,7 +387,7 @@ function App() { // connection stays configured after this screen. if (sessionRole === 'admin') { const saved = await api.saveSettings(config) - setConfig(saved.config) + applyServerConfig(saved.config) setConnections(saved.connections) } await transitionEntryStage(response.jellyfinUsers.length ? 'profiles' : 'onboarding') @@ -415,7 +428,7 @@ function App() { setNotice('') try { const response = await api.saveSettings(config) - setConfig(response.config) + applyServerConfig(response.config) setConnections(response.connections) await refreshBaseData() setNotice('Settings saved and services refreshed.') @@ -533,7 +546,7 @@ function App() { throw new Error('This file is not an OmniArr backup.') } const response = await api.importBackup(backup) - setConfig(response.config) + applyServerConfig(response.config) setConnections(response.connections) await refreshBaseData() setNotice('Backup restored.') @@ -636,6 +649,7 @@ function App() { (key: K, value: AppConfig[K]) => void options: ServiceOptionsResponse @@ -4254,7 +4272,7 @@ function SettingsView(props: { busy: boolean formId?: string }) { - const check = { busy: props.busy, onCheck: props.onCheck } + const check = { busy: props.busy, onCheck: props.onCheck, dirty: props.dirty } const importInputRef = useRef(null) return ( @@ -4405,13 +4423,20 @@ function notCheckedYet(key: ConnectionStatus['key']): ConnectionStatus { return { key, label: SERVICE_LABELS[key], ok: false, message: 'Not configured', configured: false, optional: key !== 'jellyfin' } } -function SettingsCard({ title, status, busy, onCheck, children }: { title: string; status?: ConnectionStatus; busy?: boolean; onCheck?: () => Promise; children: ReactNode }) { +function SettingsCard({ title, status, busy, dirty, onCheck, children }: { title: string; status?: ConnectionStatus; busy?: boolean; dirty?: boolean; onCheck?: () => Promise; children: ReactNode }) { return (

{title}

{onCheck ? ( - ) : null} diff --git a/src/index.css b/src/index.css index 7b72b26..3fbdf55 100644 --- a/src/index.css +++ b/src/index.css @@ -3991,6 +3991,23 @@ img { opacity: 0.5; } +/* Unsaved changes: the button turns amber and pulses until they are applied. */ +.settings-card-check.is-dirty { + background: #f6ad55; + animation: settings-check-pulse 1.8s ease-in-out infinite; +} + +@keyframes settings-check-pulse { + 0%, 100% { box-shadow: 0 0 0 0 rgba(246, 173, 85, 0.5); } + 50% { box-shadow: 0 0 0 0.45rem rgba(246, 173, 85, 0); } +} + +@media (prefers-reduced-motion: reduce) { + .settings-card-check.is-dirty { + animation: none; + } +} + .settings-card label, .auth-form label { display: grid;