Skip to content

Commit 02c48fc

Browse files
authored
impr(leaderboard): show typing speed in selected unit (@fehmer) (monkeytypegame#6328)
1 parent aaa519b commit 02c48fc

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

frontend/src/html/pages/leaderboards.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
<tr>
5252
<td>#</td>
5353
<td>name</td>
54-
<td class="stat narrow">
54+
<td class="stat narrow speedUnit">
5555
wpm
5656
<div class="sub">accuracy</div>
5757
</td>
5858
<td class="stat narrow">
5959
raw
6060
<div class="sub">consistency</div>
6161
</td>
62-
<td class="stat wide">wpm</td>
62+
<td class="stat wide speedUnit">wpm</td>
6363
<td class="stat wide">accuracy</td>
6464
<td class="stat wide">raw</td>
6565
<td class="stat wide">consistency</td>

frontend/src/ts/pages/leaderboards.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Page from "./page";
22
import * as Skeleton from "../utils/skeleton";
3+
import Config from "../config";
34
import {
45
LeaderboardEntry,
56
XpLeaderboardEntry,
@@ -39,6 +40,8 @@ import {
3940
serialize as serializeUrlSearchParams,
4041
} from "zod-urlsearchparams";
4142
import { UTCDateMini } from "@date-fns/utc";
43+
import * as ConfigEvent from "../observables/config-event";
44+
import * as ActivePage from "../states/active-page";
4245
// import * as ServerConfiguration from "../ape/server-configuration";
4346

4447
const LeaderboardTypeSchema = z.enum(["allTime", "weekly", "daily"]);
@@ -699,7 +702,10 @@ function fillUser(): void {
699702
let str = `Not qualified`;
700703

701704
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+
})})`;
703709
}
704710

705711
$(".page.pageLeaderboards .bigUser").html(
@@ -772,7 +778,7 @@ function fillUser(): void {
772778
<div class="bottom">${diffText}</div>
773779
</div>
774780
<div class="stat wide">
775-
<div class="title">wpm</div>
781+
<div class="title">${Config.typingSpeedUnit}</div>
776782
<div class="value">${formatted.wpm}</div>
777783
</div>
778784
<div class="stat wide">
@@ -943,6 +949,12 @@ function updateContent(): void {
943949
updateTimerVisibility();
944950
fillTable();
945951

952+
for (const element of document.querySelectorAll(
953+
".page.pageLeaderboards .speedUnit"
954+
)) {
955+
element.innerHTML = Config.typingSpeedUnit;
956+
}
957+
946958
if (state.scrollToUserAfterFill) {
947959
const windowHeight = $(window).height() ?? 0;
948960
const offset = $(`.tableAndUser .me`).offset()?.top ?? 0;
@@ -1338,10 +1350,17 @@ export const page = new Page({
13381350
},
13391351
afterShow: async (): Promise<void> => {
13401352
updateSecondaryButtons();
1341-
state.discordAvatarUrls = new Map<string, string>();
13421353
},
13431354
});
13441355

13451356
$(async () => {
13461357
Skeleton.save("pageLeaderboards");
13471358
});
1359+
1360+
ConfigEvent.subscribe((eventKey) => {
1361+
if (ActivePage.get() === "leaderboards" && eventKey === "typingSpeedUnit") {
1362+
updateContent();
1363+
fillUser();
1364+
fillAvatars();
1365+
}
1366+
});

0 commit comments

Comments
 (0)