diff --git a/frontend/src/ts/controllers/route-controller.ts b/frontend/src/ts/controllers/route-controller.ts index 482f8f9affc6..f40f08b31e85 100644 --- a/frontend/src/ts/controllers/route-controller.ts +++ b/frontend/src/ts/controllers/route-controller.ts @@ -314,6 +314,6 @@ document.addEventListener("DOMContentLoaded", () => { // Subscribe to navigation events from modules that can't directly import navigate // due to circular dependency constraints -NavigationEvent.subscribe((url, options) => { - void navigate(url, options); +NavigationEvent.subscribe((event) => { + void navigate(event.url, event); }); diff --git a/frontend/src/ts/observables/navigation-event.ts b/frontend/src/ts/observables/navigation-event.ts index c35ba3f72d43..84297904055b 100644 --- a/frontend/src/ts/observables/navigation-event.ts +++ b/frontend/src/ts/observables/navigation-event.ts @@ -1,9 +1,11 @@ -type NavigateOptions = { +type NavigationEvent = { + url: string; + data?: unknown; force?: boolean; tribeOverride?: boolean; }; -type SubscribeFunction = (url: string, options?: NavigateOptions) => void; +type SubscribeFunction = (event: NavigationEvent) => void; const subscribers: SubscribeFunction[] = []; @@ -11,12 +13,12 @@ export function subscribe(fn: SubscribeFunction): void { subscribers.push(fn); } -export function dispatch(url: string, options?: NavigateOptions): void { +export function dispatch(event: NavigationEvent): void { subscribers.forEach((fn) => { try { - fn(url, options); + fn(event); } catch (e) { - console.error("Navigate event subscriber threw an error"); + console.error("Navigation event subscriber threw an error"); console.error(e); } }); diff --git a/frontend/src/ts/tribe/tribe.ts b/frontend/src/ts/tribe/tribe.ts index 27988ba92d2f..3c1e46b16145 100644 --- a/frontend/src/ts/tribe/tribe.ts +++ b/frontend/src/ts/tribe/tribe.ts @@ -392,7 +392,7 @@ TribeSocket.in.room.left(() => { updateState(1); TribePageMenu.enableButtons(); if (!$(".pageTribe").hasClass("active")) { - NavigationEvent.dispatch("/tribe"); + NavigationEvent.dispatch({ url: "/tribe" }); } TribeCarets.destroyAll(); TribeSound.play("leave"); @@ -521,9 +521,7 @@ TribeSocket.in.room.initRace((data) => { } else { //TODO update lobby bars if (ActivePage.get() !== "tribe") { - NavigationEvent.dispatch("/tribe", { - tribeOverride: true, - }); + NavigationEvent.dispatch({ url: "/tribe", tribeOverride: true }); } TribeBars.init("tribe"); TribeBars.show("tribe"); @@ -531,10 +529,7 @@ TribeSocket.in.room.initRace((data) => { } if (room) room.seed = data.seed; Random.setSeed(TribeState.getRoom()?.seed.toString() ?? ""); - NavigationEvent.dispatch("/", { - tribeOverride: true, - force: true, - }); + NavigationEvent.dispatch({ url: "/", tribeOverride: true, force: true }); TribeDelta.reset(); TribeDelta.showBar(); TribeCountdown.show2(); @@ -766,7 +761,7 @@ TribeSocket.in.room.readyTimerOver(() => { }); TribeSocket.in.room.backToLobby(() => { - NavigationEvent.dispatch("/tribe"); + NavigationEvent.dispatch({ url: "/tribe" }); }); TribeSocket.in.room.finalPositions((data) => {