mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-26 18:09:40 +08:00
refactor: align navigation-event with main branch pattern
This commit is contained in:
parent
77b4c6db88
commit
ca815a6079
3 changed files with 13 additions and 16 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue