Skip to content

Commit 82422a2

Browse files
authored
Merge branch 'master' into add-correct-below-option
2 parents fc991c1 + 52b7d96 commit 82422a2

File tree

15 files changed

+182
-30
lines changed

15 files changed

+182
-30
lines changed

frontend/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
"not op_mini all",
3232
"not dead"
3333
],
34+
"lint-staged": {
35+
"*.{json,scss,css,html}": [
36+
"prettier --write"
37+
],
38+
"*.{ts,js}": [
39+
"prettier --write",
40+
"oxlint",
41+
"eslint"
42+
]
43+
},
3444
"devDependencies": {
3545
"@fortawesome/fontawesome-free": "5.15.4",
3646
"@monkeytype/eslint-config": "workspace:*",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Plugin } from "vite";
2+
import { readdirSync, readFileSync } from "fs";
3+
import { TextEncoder } from "util";
4+
import { createHash } from "crypto";
5+
6+
const virtualModuleId = "virtual:language-hashes";
7+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
8+
let skip = false;
9+
10+
export function languageHashes(): Plugin {
11+
return {
12+
name: "virtual-language-hashes",
13+
resolveId(id) {
14+
if (id === virtualModuleId) return resolvedVirtualModuleId;
15+
return;
16+
},
17+
load(id) {
18+
if (id === resolvedVirtualModuleId) {
19+
const hashes: Record<string, string> = skip ? {} : getHashes();
20+
return `
21+
export const languageHashes = ${JSON.stringify(hashes)};
22+
`;
23+
}
24+
return;
25+
},
26+
configResolved(resolvedConfig) {
27+
if (resolvedConfig?.define?.["IS_DEVELOPMENT"] === "true") {
28+
skip = true;
29+
console.log("Skipping language hashing in dev environment.");
30+
}
31+
},
32+
};
33+
}
34+
35+
function getHashes(): Record<string, string> {
36+
const start = performance.now();
37+
38+
console.log("\nHashing languages...");
39+
40+
const hashes = Object.fromEntries(
41+
readdirSync("./static/languages").map((file) => {
42+
return [file.slice(0, -5), calcHash(file)];
43+
})
44+
);
45+
46+
const end = performance.now();
47+
48+
console.log(`Creating language hashes took ${Math.round(end - start)} ms`);
49+
50+
return hashes;
51+
}
52+
53+
function calcHash(file: string): string {
54+
const currentLanguage = JSON.stringify(
55+
JSON.parse(readFileSync("./static/languages/" + file).toString()),
56+
null,
57+
0
58+
);
59+
const encoder = new TextEncoder();
60+
const data = encoder.encode(currentLanguage);
61+
return createHash("sha256").update(data).digest("hex");
62+
}
63+
64+
if (import.meta.url.endsWith(process.argv[1] as string)) {
65+
console.log(JSON.stringify(getHashes(), null, 4));
66+
}

frontend/src/html/pages/leaderboards.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,21 @@
4949
<table>
5050
<thead class="allTimeAndDaily">
5151
<tr>
52-
<td><i class="fas fa-users"></i></td>
53-
<td>#</td>
52+
<td>
53+
<span aria-label="Friends rank" data-balloon-pos="down">
54+
<i class="fas fa-user-friends"></i>
55+
</span>
56+
</td>
57+
<td>
58+
<span
59+
class="globalRank"
60+
aria-label="Global rank"
61+
data-balloon-pos="down"
62+
>
63+
<span>#</span>
64+
<i class="fas fa-users"></i>
65+
</span>
66+
</td>
5467
<td>name</td>
5568
<td class="stat narrow speedUnit">
5669
<span>wpm</span>

frontend/src/security-policy.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ <h1 id="Vulnerability_Disclosure">How to Disclose a Vulnerability</h1>
137137
<a href="mailto:contact@monkeytype.com" rel="noopener">email</a>
138138
.
139139
</span>
140-
For non-security related platform bugs, follow the bug submission
140+
&nbsp;For non-security related platform bugs, follow the bug
141+
submission
141142
<span style="display: inline-flex">
142143
<a
143144
href="https://github.com/monkeytypegame/monkeytype#bug-report-or-feature-request"
@@ -146,8 +147,8 @@ <h1 id="Vulnerability_Disclosure">How to Disclose a Vulnerability</h1>
146147
</a>
147148
.
148149
</span>
149-
Include as much detail as possible to ensure reproducibility. At a
150-
minimum, vulnerability disclosures should include:
150+
&nbsp;Include as much detail as possible to ensure reproducibility. At
151+
a minimum, vulnerability disclosures should include:
151152
</p>
152153
<ul>
153154
<li>Vulnerability Description</li>

frontend/src/styles/leaderboards.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,26 @@
161161
padding: var(--padding);
162162
}
163163

164+
.globalRank {
165+
i {
166+
display: none;
167+
}
168+
span {
169+
display: inline;
170+
}
171+
}
164172
&.friendsOnly {
165173
td:first-child {
166174
display: table-cell;
167175
}
176+
.globalRank {
177+
i {
178+
display: inline;
179+
}
180+
span {
181+
display: none;
182+
}
183+
}
168184
}
169185
td:first-child {
170186
display: none;

frontend/src/ts/controllers/route-controller.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ type Route = {
4747

4848
const route404: Route = {
4949
path: "404",
50-
load: async () => {
51-
await PageController.change("404");
50+
load: async (_params, options) => {
51+
await PageController.change("404", options);
5252
},
5353
};
5454

@@ -224,7 +224,12 @@ async function router(options = {} as NavigateOptions): Promise<void> {
224224
};
225225

226226
if (match === undefined) {
227-
await route404.load({}, {});
227+
await route404.load(
228+
{},
229+
{
230+
force: true,
231+
}
232+
);
228233
return;
229234
}
230235

frontend/src/ts/module.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Language } from "@monkeytype/schemas/languages";
2+
3+
declare module "virtual:language-hashes" {
4+
export const languageHashes: Record<Language, string>;
5+
}

frontend/src/ts/pages/leaderboards.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,8 @@ function buildTableRow(entry: LeaderboardEntry, me = false): HTMLElement {
444444
}
445445
element.dataset["uid"] = entry.uid;
446446
element.innerHTML = `
447-
<td>${entry.friendsRank ?? ""}</td>
448-
<td>${
449-
entry.rank === 1 ? '<i class="fas fa-fw fa-crown"></i>' : entry.rank
450-
}</td>
447+
<td>${formatRank(entry.friendsRank)}</td>
448+
<td>${formatRank(entry.rank)}</td>
451449
<td>
452450
<div class="avatarNameBadge">
453451
<div class="avatarPlaceholder"></div>
@@ -504,9 +502,7 @@ function buildWeeklyTableRow(
504502
element.dataset["uid"] = entry.uid;
505503
element.innerHTML = `
506504
<td></td>
507-
<td>${
508-
entry.rank === 1 ? '<i class="fas fa-fw fa-crown"></i>' : entry.rank
509-
}</td>
505+
<td>${formatRank(entry.rank)}</td>
510506
<td>
511507
<div class="avatarNameBadge">
512508
<div class="avatarPlaceholder"></div>
@@ -718,9 +714,7 @@ function fillUser(): void {
718714
};
719715

720716
const html = `
721-
<div class="rank">${
722-
rank === 1 ? '<i class="fas fa-fw fa-crown"></i>' : rank
723-
}</div>
717+
<div class="rank">${formatRank(rank)}</div>
724718
<div class="userInfo">
725719
<div class="top">You (${percentileString})</div>
726720
<div class="bottom">${diffText}</div>
@@ -811,11 +805,7 @@ function fillUser(): void {
811805
};
812806

813807
const html = `
814-
<div class="rank">${
815-
userData.rank === 1
816-
? '<i class="fas fa-fw fa-crown"></i>'
817-
: userData.rank
818-
}</div>
808+
<div class="rank">${formatRank(userData.rank)}</div>
819809
<div class="userInfo">
820810
<div class="top">You (${percentileString})</div>
821811
<div class="bottom">${diffText}</div>
@@ -1390,6 +1380,13 @@ function updateTimeText(
13901380
text.attr("aria-label", localDateString);
13911381
}
13921382

1383+
function formatRank(rank: number | undefined): string {
1384+
if (rank === undefined) return "";
1385+
if (rank === 1) return '<i class="fas fa-fw fa-crown"></i>';
1386+
1387+
return rank.toString();
1388+
}
1389+
13931390
$(".page.pageLeaderboards .jumpButtons button").on("click", function () {
13941391
const action = $(this).data("action") as Action;
13951392
if (action !== "goToPage") {

frontend/src/ts/sentry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export async function activateSentry(): Promise<void> {
2626
environment: envConfig.isDevelopment ? "development" : "production",
2727
integrations: [
2828
Sentry.browserTracingIntegration(),
29-
Sentry.replayIntegration({
30-
unmask: ["#notificationCenter"],
31-
block: ["#commandLine .modal .suggestions"],
32-
}),
29+
// Sentry.replayIntegration({
30+
// unmask: ["#notificationCenter"],
31+
// block: ["#commandLine .modal .suggestions"],
32+
// }),
3333
Sentry.thirdPartyErrorFilterIntegration({
3434
filterKeys: ["monkeytype-frontend"],
3535
// Defines how to handle errors that contain third party stack frames.

frontend/src/ts/test/test-logic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ async function init(): Promise<boolean> {
456456
}
457457

458458
if (!language || language.name !== Config.language) {
459-
UpdateConfig.setLanguage("english");
460459
return await init();
461460
}
462461

0 commit comments

Comments
 (0)