From 3006209ecc0cd447d06918656b9d2cdcbca0a51e Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Fri, 11 Jul 2025 17:45:19 -0500 Subject: [PATCH] Add rehash dialog type state and enhance confirmation handling for settings save and rehash --- frontend/src/pages/Settings.jsx | 76 ++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index 1518d91c..7533637b 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -54,6 +54,9 @@ const SettingsPage = () => { const [rehashSuccess, setRehashSuccess] = useState(false); const [rehashConfirmOpen, setRehashConfirmOpen] = useState(false); + // Add a new state to track the dialog type + const [rehashDialogType, setRehashDialogType] = useState(null); // 'save' or 'rehash' + // UI / local storage settings const [tableSize, setTableSize] = useLocalStorage('table-size', 'default'); @@ -179,6 +182,7 @@ const SettingsPage = () => { // If M3U hash key changed, show warning (unless suppressed) if (m3uHashKeyChanged && !isWarningSuppressed('rehash-streams')) { + setRehashDialogType('save'); // Set dialog type to save setRehashConfirmOpen(true); return; } @@ -264,32 +268,6 @@ const SettingsPage = () => { } }; - const onRehashStreams = async () => { - // Skip warning if it's been suppressed - if (isWarningSuppressed('rehash-streams')) { - return executeRehashStreams(); - } - - setRehashConfirmOpen(true); - }; - - const executeRehashStreams = async () => { - setRehashingStreams(true); - setRehashSuccess(false); - setRehashConfirmOpen(false); - - try { - await API.rehashStreams(); - setRehashSuccess(true); - setTimeout(() => setRehashSuccess(false), 5000); // Clear success message after 5 seconds - } catch (error) { - console.error('Error rehashing streams:', error); - // You might want to add error state handling here - } finally { - setRehashingStreams(false); - } - }; - const executeSettingsSaveAndRehash = async () => { setRehashConfirmOpen(false); @@ -312,6 +290,41 @@ const SettingsPage = () => { } }; + const executeRehashStreamsOnly = async () => { + setRehashingStreams(true); + setRehashSuccess(false); + setRehashConfirmOpen(false); + + try { + await API.rehashStreams(); + setRehashSuccess(true); + setTimeout(() => setRehashSuccess(false), 5000); + } catch (error) { + console.error('Error rehashing streams:', error); + } finally { + setRehashingStreams(false); + } + }; + + const onRehashStreams = async () => { + // Skip warning if it's been suppressed + if (isWarningSuppressed('rehash-streams')) { + return executeRehashStreamsOnly(); + } + + setRehashDialogType('rehash'); // Set dialog type to rehash + setRehashConfirmOpen(true); + }; + + // Create a function to handle the confirmation based on dialog type + const handleRehashConfirm = () => { + if (rehashDialogType === 'save') { + executeSettingsSaveAndRehash(); + } else { + executeRehashStreamsOnly(); + } + }; + return (
{ setRehashConfirmOpen(false)} - onConfirm={executeSettingsSaveAndRehash} - title="Confirm Stream Rehash" + onClose={() => { + setRehashConfirmOpen(false); + setRehashDialogType(null); + }} + onConfirm={handleRehashConfirm} + title={rehashDialogType === 'save' ? 'Save Settings and Rehash Streams' : 'Confirm Stream Rehash'} message={
{`Are you sure you want to rehash all streams? @@ -687,7 +703,7 @@ M3U refreshes will be blocked until this process finishes. Please ensure you have time to let this complete before proceeding.`}
} - confirmLabel="Save & Start Rehash" + confirmLabel={rehashDialogType === 'save' ? 'Save and Rehash' : 'Start Rehash'} cancelLabel="Cancel" actionKey="rehash-streams" onSuppressChange={suppressWarning}