Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/ts/controllers/route-controller.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains a NavigateOptions type that is similar to the NavigationEvent maybe you can reuse/combine it and use in the navigate function.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
12 changes: 7 additions & 5 deletions frontend/src/ts/observables/navigation-event.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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[] = [];

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);
}
});
Expand Down
13 changes: 4 additions & 9 deletions frontend/src/ts/tribe/tribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -521,20 +521,15 @@ 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");
return;
}
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();
Expand Down Expand Up @@ -766,7 +761,7 @@ TribeSocket.in.room.readyTimerOver(() => {
});

TribeSocket.in.room.backToLobby(() => {
NavigationEvent.dispatch("/tribe");
NavigationEvent.dispatch({ url: "/tribe" });
});

TribeSocket.in.room.finalPositions((data) => {
Expand Down