Fix race-audio Test buttons silently saving settings to the database

Clicking a Test button (general or per-event) in the race-sounds table
called persistRaceAudioFormValues, which both applied the form's
current values and saved them to the backend on every click. A sound
preview should only apply values in memory, not persist them - split
into an apply-only helper used by the Test buttons, keeping the
existing save behavior for the explicit Save button and field changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
larssand
2026-09-10 19:28:46 +02:00
parent cc9f5c380b
commit f988ad2690
5 changed files with 28 additions and 5 deletions

View File

@@ -659,11 +659,16 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
});
};
const persistRaceAudioFormValues = () => {
const applyRaceAudioFormValuesFromDom = () => {
const formNode = document.getElementById("settingsForm");
if (!(formNode instanceof HTMLFormElement)) return false;
applyRaceAudioFormValues(new FormData(formNode));
state.settings.audioEnabled = state.settings.audioEnabled || state.settings.raceAudio.enabled;
return true;
};
const persistRaceAudioFormValues = () => {
if (!applyRaceAudioFormValuesFromDom()) return false;
saveState();
return true;
};
@@ -755,7 +760,10 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
});
document.getElementById("settingsSaveRaceAudio")?.addEventListener("click", persistRaceAudioFormValues);
const testRaceAudio = (eventKey) => {
persistRaceAudioFormValues();
// Uses whatever's currently in the form (including unsaved edits) so a test preview
// matches what you're about to hear - but a test playback is not itself a reason to
// write those still-unsaved changes to the database. Use the explicit Save button for that.
applyRaceAudioFormValuesFromDom();
triggerRaceAudio(eventKey, { force: true, interrupt: true, variables: { driverName: state.drivers[0]?.name || "Driver", lapTime: "16.000", marshalPost: "1", transponder: "123", podium: "P1, P2, P3" } });
};
document.getElementById("settingsRaceAudioTest")?.addEventListener("click", () => testRaceAudio("audio_test"));