Skip to content

Commit e5b0978

Browse files
byseif21Miodec
andauthored
fix(settings): ensure themes UI is always up-to-date when renavigating (@byseif21) (monkeytypegame#6581)
### Description When (changing / adding or removing themes from favorite ) via command line or from the current theme button "in page e.g test page" and then navigating to Settings > Themes, the UI does not immediately reflect the current theme changes . The user has to manually refresh the page to see these changes. **Now** UI automatically refreshes to reflect the current theme selection and favorites without requiring a manual page refresh. - Added refreshThemeUI function in theme-picker.ts that updates all theme-related UI components - Called this refresh function in the settings page's beforeShow lifecycle hook to ensure the theme UI is always up-to-date when the page is displayed. **FOR TESTING BEFORE & AFTER:** keep changing themes then navigate to the settings and check and keep doing those things again to verify that the active theme and favorites update. --------- Co-authored-by: Miodec <[email protected]>
1 parent 21230ab commit e5b0978

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

frontend/src/ts/elements/settings/theme-picker.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function updateColors(
115115
colorPicker.find("input.color").val(color);
116116
}
117117

118-
export async function refreshPresetButtons(): Promise<void> {
118+
export async function fillPresetButtons(): Promise<void> {
119119
// Update theme buttons
120120
const favThemesEl = document.querySelector<HTMLElement>(
121121
".pageSettings .section.themes .favThemes.buttons"
@@ -211,7 +211,7 @@ export async function refreshPresetButtons(): Promise<void> {
211211
themesEl.innerHTML = themesElHTML;
212212
}
213213

214-
export async function refreshCustomButtons(): Promise<void> {
214+
export async function fillCustomButtons(): Promise<void> {
215215
// Update custom theme buttons
216216
const customThemesEl = $(
217217
".pageSettings .section.themes .allCustomThemes.buttons"
@@ -318,6 +318,12 @@ export function updateActiveTab(): void {
318318
}
319319
}
320320

321+
// separated to avoid repeated calls
322+
export async function updateThemeUI(): Promise<void> {
323+
await fillPresetButtons();
324+
updateActiveButton();
325+
}
326+
321327
// Add events to the DOM
322328

323329
// Handle click on theme: preset or custom tab
@@ -363,7 +369,6 @@ $(".pageSettings").on("click", ".section.themes .theme .favButton", (e) => {
363369
.attr("theme") as ThemeName;
364370
if (theme !== undefined) {
365371
toggleFavourite(theme);
366-
void refreshPresetButtons();
367372
} else {
368373
console.error(
369374
"Could not find the theme attribute attached to the button clicked!"
@@ -472,14 +477,14 @@ $(".pageSettings #saveCustomThemeButton").on("click", async () => {
472477
await DB.addCustomTheme(newCustomTheme);
473478
Loader.hide();
474479
}
475-
void refreshCustomButtons();
480+
void fillCustomButtons();
476481
});
477482

478483
ConfigEvent.subscribe((eventKey) => {
479484
if (eventKey === "theme" && ActivePage.get() === "settings") {
480485
updateActiveButton();
481486
}
482487
if (eventKey === "favThemes" && ActivePage.get() === "settings") {
483-
void refreshPresetButtons();
488+
void fillPresetButtons();
484489
}
485490
});

frontend/src/ts/modals/simple-modals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ list.updateCustomTheme = new SimpleModal({
11521152
};
11531153
}
11541154
UpdateConfig.setCustomThemeColors(newColors as CustomThemeColors);
1155-
void ThemePicker.refreshCustomButtons();
1155+
void ThemePicker.fillCustomButtons();
11561156

11571157
return {
11581158
status: 1,
@@ -1179,7 +1179,7 @@ list.deleteCustomTheme = new SimpleModal({
11791179
onlineOnly: true,
11801180
execFn: async (_thisPopup): Promise<ExecReturn> => {
11811181
await DB.deleteCustomTheme(_thisPopup.parameters[0] as string);
1182-
void ThemePicker.refreshCustomButtons();
1182+
void ThemePicker.fillCustomButtons();
11831183

11841184
return {
11851185
status: 1,

frontend/src/ts/pages/settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,7 @@ async function fillSettingsPage(): Promise<void> {
686686
setEventDisabled(true);
687687

688688
await initGroups();
689-
await ThemePicker.refreshCustomButtons();
690-
await ThemePicker.refreshPresetButtons();
689+
await ThemePicker.fillCustomButtons();
691690

692691
setEventDisabled(false);
693692
settingsInitialized = true;
@@ -819,7 +818,6 @@ export async function update(
819818
await Misc.sleep(0);
820819
ThemePicker.updateActiveTab();
821820
ThemePicker.setCustomInputs(true);
822-
// ThemePicker.updateActiveButton();
823821

824822
const setInputValue = (
825823
key: ConfigKey,
@@ -1271,6 +1269,8 @@ export const page = new PageWithUrlParams({
12711269
await UpdateConfig.loadPromise;
12721270
await fillSettingsPage();
12731271
await update();
1272+
// theme UI updates manually to avoid duplication
1273+
await ThemePicker.updateThemeUI();
12741274

12751275
handleHighlightSection(options.urlParams?.highlight);
12761276
},

0 commit comments

Comments
 (0)