Skip to content

Commit ac7836c

Browse files
committed
Set event when navigating to/from the results page.
1 parent b1baf08 commit ac7836c

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/timer.cubing.net/app/TimerApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class TimerApp {
5353
this.session.startSync(this.onSyncChange.bind(this));
5454

5555
this.scrambleView = new ScrambleView(this);
56-
this.statsView = new StatsView();
56+
this.statsView = new StatsView(() => this.currentEvent);
5757
this.domElement = <HTMLElement>document.getElementById("timer-app");
5858

5959
this.enableOffline();

src/timer.cubing.net/results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<body>
3737
<p>
38-
<a href="./">Back to timer!</a><br><br>
38+
<a href="./" id="back-to-timer">Back to timer!</a><br><br>
3939
<button id="export">Export all events</button>
4040
<button id="export-to-cstimer">Export event to CSTimer (incomplete)</button>
4141
<button id="export-to-qqtimer">Export event to QQTimer format</button>

src/timer.cubing.net/ui/StatsView.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** biome-ignore-all lint/complexity/useLiteralKeys: Known Biome limitation. */
22

3+
import type { EventID } from "../app/events";
34
import type { AttemptDataWithIDAndRev } from "../results/AttemptData";
45
// import {ScrambleID} from "./scramble-worker"
56
import { trForAttempt } from "./results-table";
@@ -22,7 +23,7 @@ export class StatsView {
2223
private statsDropdown: HTMLSelectElement;
2324
private elems: { [s: string]: HTMLOptionElement };
2425
private sidebarElems: { [s: string]: HTMLOptionElement };
25-
constructor() {
26+
constructor(getCurrentEvent: () => EventID) {
2627
this.statsDropdown = <HTMLSelectElement>(
2728
document.getElementById("stats-dropdown")
2829
);
@@ -81,12 +82,10 @@ export class StatsView {
8182
);
8283
for (const resultsLink of [...resultsLinks]) {
8384
resultsLink.addEventListener("click", (e: Event) => {
85+
const url = new URL(resultsLink.href);
86+
url.searchParams.set("event", getCurrentEvent());
87+
window.location.href = url.toString();
8488
e.preventDefault();
85-
window.location.href = resultsLink.href;
86-
// Don't set event for now.
87-
// const url = new URL(resultsLink.href);
88-
// url.searchParams.set("event", getCurrentEvent())
89-
// window.location.href = url.toString();
9089
});
9190
}
9291
}

src/timer.cubing.net/ui/results-page.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,16 @@ function addEventIDOptions(): void {
8282
}
8383
}
8484

85+
function backURL(event: EventID): URL {
86+
const url = new URL("../", import.meta.url);
87+
url.searchParams.set("event", event);
88+
return url;
89+
}
90+
8591
export async function showData(): Promise<void> {
86-
const eventId = getEventID();
92+
const eventID = getEventID();
93+
document.querySelector<HTMLAnchorElement>("#back-to-timer")!.href =
94+
backURL(eventID).toString();
8795
const rangeSelector = getRangeSelector();
8896

8997
const tableBody = document.querySelector("#results tbody") as HTMLBodyElement;
@@ -96,7 +104,7 @@ export async function showData(): Promise<void> {
96104
unfilteredAttempts = (
97105
await session.mostRecentAttempts(
98106
MAX_NUM_RECENT_ATTEMPTS,
99-
eventId as EventID,
107+
eventID as EventID,
100108
rangeSelector === "most-recent",
101109
)
102110
).docs;
@@ -108,15 +116,15 @@ export async function showData(): Promise<void> {
108116
unfilteredAttempts = await session.extremeTimes(
109117
MAX_NUM_RECENT_ATTEMPTS,
110118
rangeSelector === "worst",
111-
eventId as EventID,
119+
eventID as EventID,
112120
);
113121
break;
114122
}
115123
default:
116124
throw new Error("unexpected range selector");
117125
}
118126
const attempts = unfilteredAttempts.filter(
119-
(attempt: AttemptData) => attempt.event === eventId,
127+
(attempt: AttemptData) => attempt.event === eventID,
120128
);
121129
for (const attempt of attempts) {
122130
if (!attempt.totalResultMs) {

0 commit comments

Comments
 (0)