Skip to content

Commit d8fd641

Browse files
authored
fix: filter section doesn't toggle using local image (@byseif21) (monkeytypegame#6796)
1 parent d48ddca commit d8fd641

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

frontend/src/ts/controllers/theme-controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ export async function applyCustomBackground(): Promise<void> {
392392
backgroundUrl = localBackgroundFile;
393393
}
394394

395+
// hide the filter section initially and always
396+
$(
397+
".pageSettings .section[data-config-name='customBackgroundFilter']"
398+
).addClass("hidden");
399+
395400
if (backgroundUrl === "") {
396401
$("#words").removeClass("noErrorBorder");
397402
$("#resultWordsHistory").removeClass("noErrorBorder");
@@ -409,6 +414,13 @@ export async function applyCustomBackground(): Promise<void> {
409414
"onError",
410415
"javascript:this.style.display='none'; window.dispatchEvent(new Event('customBackgroundFailed'))"
411416
);
417+
img.onload = () => {
418+
// show the filter section only if the image loads successfully
419+
$(
420+
".pageSettings .section[data-config-name='customBackgroundFilter']"
421+
).removeClass("hidden");
422+
};
423+
412424
container?.replaceChildren(img);
413425

414426
BackgroundFilter.apply();

frontend/src/ts/pages/settings.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,23 @@ function refreshPresetsSettingsSection(): void {
803803
}
804804
}
805805

806+
export async function updateFilterSectionVisibility(): Promise<void> {
807+
const hasBackgroundUrl =
808+
Config.customBackground !== "" ||
809+
(await FileStorage.hasFile("LocalBackgroundFile"));
810+
const isImageVisible = $(".customBackground img").is(":visible");
811+
812+
if (hasBackgroundUrl && isImageVisible) {
813+
$(
814+
".pageSettings .section[data-config-name='customBackgroundFilter']"
815+
).removeClass("hidden");
816+
} else {
817+
$(
818+
".pageSettings .section[data-config-name='customBackgroundFilter']"
819+
).addClass("hidden");
820+
}
821+
}
822+
806823
export async function update(
807824
options: {
808825
eventKey?: ConfigEvent.ConfigEventKey;
@@ -832,6 +849,7 @@ export async function update(
832849
ThemePicker.updateActiveTab();
833850
ThemePicker.setCustomInputs(true);
834851
await CustomBackgroundPicker.updateUI();
852+
await updateFilterSectionVisibility();
835853

836854
const setInputValue = (
837855
key: ConfigKey,
@@ -887,19 +905,6 @@ export async function update(
887905
).addClass("hidden");
888906
}
889907

890-
if (
891-
Config.customBackground !== "" ||
892-
(await FileStorage.hasFile("LocalBackgroundFile"))
893-
) {
894-
$(
895-
".pageSettings .section[data-config-name='customBackgroundFilter']"
896-
).removeClass("hidden");
897-
} else {
898-
$(
899-
".pageSettings .section[data-config-name='customBackgroundFilter']"
900-
).addClass("hidden");
901-
}
902-
903908
setInputValue(
904909
"fontSize",
905910
".pageSettings .section[data-config-name='fontSize'] input",
@@ -1207,7 +1212,9 @@ ConfigEvent.subscribe((eventKey, eventValue) => {
12071212
//make sure the page doesnt update a billion times when applying a preset/config at once
12081213
if (configEventDisabled || eventKey === "saveToLocalStorage") return;
12091214
if (ActivePage.get() === "settings" && eventKey !== "theme") {
1210-
void update({ eventKey });
1215+
void (eventKey === "customBackground"
1216+
? updateFilterSectionVisibility()
1217+
: update({ eventKey }));
12111218
}
12121219
});
12131220

0 commit comments

Comments
 (0)