|
1 | 1 | import Page from "./page"; |
2 | 2 | import * as Skeleton from "../utils/skeleton"; |
| 3 | +import Config from "../config"; |
3 | 4 | import { |
4 | 5 | LeaderboardEntry, |
5 | 6 | XpLeaderboardEntry, |
@@ -39,6 +40,8 @@ import { |
39 | 40 | serialize as serializeUrlSearchParams, |
40 | 41 | } from "zod-urlsearchparams"; |
41 | 42 | import { UTCDateMini } from "@date-fns/utc"; |
| 43 | +import * as ConfigEvent from "../observables/config-event"; |
| 44 | +import * as ActivePage from "../states/active-page"; |
42 | 45 | // import * as ServerConfiguration from "../ape/server-configuration"; |
43 | 46 |
|
44 | 47 | const LeaderboardTypeSchema = z.enum(["allTime", "weekly", "daily"]); |
@@ -699,7 +702,10 @@ function fillUser(): void { |
699 | 702 | let str = `Not qualified`; |
700 | 703 |
|
701 | 704 | if (!state.yesterday) { |
702 | | - str += ` (min speed required: ${state.minWpm} wpm)`; |
| 705 | + str += ` (min speed required: ${Format.typingSpeed(state.minWpm, { |
| 706 | + showDecimalPlaces: true, |
| 707 | + suffix: ` ${Config.typingSpeedUnit}`, |
| 708 | + })})`; |
703 | 709 | } |
704 | 710 |
|
705 | 711 | $(".page.pageLeaderboards .bigUser").html( |
@@ -772,7 +778,7 @@ function fillUser(): void { |
772 | 778 | <div class="bottom">${diffText}</div> |
773 | 779 | </div> |
774 | 780 | <div class="stat wide"> |
775 | | - <div class="title">wpm</div> |
| 781 | + <div class="title">${Config.typingSpeedUnit}</div> |
776 | 782 | <div class="value">${formatted.wpm}</div> |
777 | 783 | </div> |
778 | 784 | <div class="stat wide"> |
@@ -943,6 +949,12 @@ function updateContent(): void { |
943 | 949 | updateTimerVisibility(); |
944 | 950 | fillTable(); |
945 | 951 |
|
| 952 | + for (const element of document.querySelectorAll( |
| 953 | + ".page.pageLeaderboards .speedUnit" |
| 954 | + )) { |
| 955 | + element.innerHTML = Config.typingSpeedUnit; |
| 956 | + } |
| 957 | + |
946 | 958 | if (state.scrollToUserAfterFill) { |
947 | 959 | const windowHeight = $(window).height() ?? 0; |
948 | 960 | const offset = $(`.tableAndUser .me`).offset()?.top ?? 0; |
@@ -1338,10 +1350,17 @@ export const page = new Page({ |
1338 | 1350 | }, |
1339 | 1351 | afterShow: async (): Promise<void> => { |
1340 | 1352 | updateSecondaryButtons(); |
1341 | | - state.discordAvatarUrls = new Map<string, string>(); |
1342 | 1353 | }, |
1343 | 1354 | }); |
1344 | 1355 |
|
1345 | 1356 | $(async () => { |
1346 | 1357 | Skeleton.save("pageLeaderboards"); |
1347 | 1358 | }); |
| 1359 | + |
| 1360 | +ConfigEvent.subscribe((eventKey) => { |
| 1361 | + if (ActivePage.get() === "leaderboards" && eventKey === "typingSpeedUnit") { |
| 1362 | + updateContent(); |
| 1363 | + fillUser(); |
| 1364 | + fillAvatars(); |
| 1365 | + } |
| 1366 | +}); |
0 commit comments