mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-04 02:34:43 +08:00
feat: detect custom background image not available (fehmer) (#5460)
* feat: detect custom background image not available (fehmer) * settings page not updating custom background input if config changes * cleanup
This commit is contained in:
parent
595000ad4f
commit
24909fda1c
2 changed files with 12 additions and 2 deletions
|
@ -4,7 +4,7 @@ import * as Misc from "../utils/misc";
|
|||
import * as Arrays from "../utils/arrays";
|
||||
import * as JSONData from "../utils/json-data";
|
||||
import { isColorDark, isColorLight } from "../utils/colors";
|
||||
import Config, { setAutoSwitchTheme } from "../config";
|
||||
import Config, { setAutoSwitchTheme, setCustomBackground } from "../config";
|
||||
import * as BackgroundFilter from "../elements/custom-background-filter";
|
||||
import * as ConfigEvent from "../observables/config-event";
|
||||
import * as DB from "../db";
|
||||
|
@ -345,7 +345,7 @@ function applyCustomBackground(): void {
|
|||
$("#words").addClass("noErrorBorder");
|
||||
$("#resultWordsHistory").addClass("noErrorBorder");
|
||||
$(".customBackground").html(
|
||||
`<img src="${Config.customBackground}" alt="" />`
|
||||
`<img src="${Config.customBackground}" alt="" onerror="javascript:window.dispatchEvent(new Event('customBackgroundFailed'))" />`
|
||||
);
|
||||
BackgroundFilter.apply();
|
||||
applyCustomBackgroundSize();
|
||||
|
@ -425,3 +425,10 @@ ConfigEvent.subscribe(async (eventKey, eventValue, nosave) => {
|
|||
await set(Config.themeDark, true);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("customBackgroundFailed", () => {
|
||||
Notifications.add(
|
||||
"The custom background cannot be loaded and will be removed from your configuration."
|
||||
);
|
||||
setCustomBackground("");
|
||||
});
|
||||
|
|
|
@ -950,6 +950,9 @@ export async function update(groupUpdate = true): Promise<void> {
|
|||
".pageSettings .section[data-config-name='customBackgroundFilter']"
|
||||
).addClass("hidden");
|
||||
}
|
||||
$(
|
||||
".pageSettings .section[data-config-name='customBackgroundSize'] input"
|
||||
).val(Config.customBackground);
|
||||
|
||||
if (isAuthenticated()) {
|
||||
showAccountSection();
|
||||
|
|
Loading…
Reference in a new issue