From b0c3e71f2ed71e477218beda15d1847556c29f84 Mon Sep 17 00:00:00 2001 From: Ryan Adler Date: Sun, 25 Aug 2024 23:28:57 +0200 Subject: [PATCH] Real fix for the Change Color button not working on first load (from root) Removed redundant calls --- src/ts/controller/mainMenuController.ts | 1 - src/ts/controller/settingsController.ts | 2 -- src/ts/routing.ts | 8 +++++--- src/ts/views/mainMenuView.ts | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ts/controller/mainMenuController.ts b/src/ts/controller/mainMenuController.ts index 71d634a5..19206281 100644 --- a/src/ts/controller/mainMenuController.ts +++ b/src/ts/controller/mainMenuController.ts @@ -28,7 +28,6 @@ export const mainMenuController = { */ changeColor() { settingsController.changeColorTheme(state.color === Color.Light ? Color.Dark : Color.Light); - mainMenuController.index(); }, /** Return page */ diff --git a/src/ts/controller/settingsController.ts b/src/ts/controller/settingsController.ts index ffb9c243..f2aa58ca 100644 --- a/src/ts/controller/settingsController.ts +++ b/src/ts/controller/settingsController.ts @@ -26,7 +26,6 @@ export const settingsController = { */ changeColorTheme(color: Color): void { template.changeColorTheme( color ); - state.updateColorTheme( color ); }, /** @@ -35,7 +34,6 @@ export const settingsController = { */ changeTextSize(textSize: TextSize): void { template.changeTextSize( textSize ); - state.updateTextSize( textSize ); }, /** diff --git a/src/ts/routing.ts b/src/ts/routing.ts index b013130d..397838c5 100644 --- a/src/ts/routing.ts +++ b/src/ts/routing.ts @@ -56,8 +56,10 @@ export const routing = { } routing.redirect(initialHash); - // Force the initial load - routing.onHashChange(); + // Force the initial load if the hashChange event will not fire automatically + if (routing.normalizeHash(location.hash) === initialHash) { + routing.onHashChange(); + } }, /** @@ -118,7 +120,7 @@ export const routing = { let controller; - // Notify the previous controler that we leave + // Notify the previous controller that we leave try { if ( routing.lastControllerName ) { controller = routing.getController(routing.lastControllerName); diff --git a/src/ts/views/mainMenuView.ts b/src/ts/views/mainMenuView.ts index 35afef85..f2de92bd 100644 --- a/src/ts/views/mainMenuView.ts +++ b/src/ts/views/mainMenuView.ts @@ -20,7 +20,7 @@ export const mainMenuView = { e.preventDefault(); routing.redirect("loadGame"); }); - $("#menu-color-theme").one("click", (e) => { + $("#menu-color-theme").on("click", (e) => { e.preventDefault(); mainMenuController.changeColor(); });