Improve logs (+add toasts) on save calls

- Fixes #2429
This commit is contained in:
Wolfsblvt
2024-06-28 03:28:16 +02:00
parent b8295ac8f5
commit 54e111886b
6 changed files with 49 additions and 26 deletions

View File

@ -2316,26 +2316,30 @@ async function saveTheme(name = undefined, theme = undefined) {
body: JSON.stringify(theme),
});
if (response.ok) {
const themeIndex = themes.findIndex(x => x.name == name);
if (themeIndex == -1) {
themes.push(theme);
const option = document.createElement('option');
option.selected = true;
option.value = name;
option.innerText = name;
$('#themes').append(option);
}
else {
themes[themeIndex] = theme;
$(`#themes option[value="${name}"]`).attr('selected', true);
}
power_user.theme = name;
saveSettingsDebounced();
if (!response.ok) {
toastr.error('Check the server connection and reload the page to prevent data loss.', 'Theme could not be saved');
console.error('Theme could not be saved', response);
return;
}
const themeIndex = themes.findIndex(x => x.name == name);
if (themeIndex == -1) {
themes.push(theme);
const option = document.createElement('option');
option.selected = true;
option.value = name;
option.innerText = name;
$('#themes').append(option);
}
else {
themes[themeIndex] = theme;
$(`#themes option[value="${name}"]`).attr('selected', true);
}
power_user.theme = name;
saveSettingsDebounced();
return theme;
}
@ -2439,6 +2443,7 @@ async function saveMovingUI() {
saveSettingsDebounced();
} else {
toastr.warning('failed to save MovingUI state.');
console.error('MovingUI could not be saved', response);
}
}