Skip to content

Commit 032844d

Browse files
committed
feat: add show personal best
you can now view the pb for current test settings right above the test words, before starting the test
1 parent eab1737 commit 032844d

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

frontend/src/ts/commandline/commandline-metadata.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
703703
options: "fromSchema",
704704
},
705705
},
706+
showPb: {
707+
subgroup: {
708+
options: "fromSchema",
709+
},
710+
alias: "pb",
711+
},
706712
monkeyPowerLevel: {
707713
alias: "powermode",
708714
isVisible: false,

frontend/src/ts/commandline/lists.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const confidenceModeCommand = buildCommandForConfigKey("confidenceMode");
5252
const lazyModeCommand = buildCommandForConfigKey("lazyMode");
5353
const layoutCommand = buildCommandForConfigKey("layout");
5454
const showAverageCommand = buildCommandForConfigKey("showAverage");
55+
const showPbCommand = buildCommandForConfigKey("showPb");
5556
const keymapLayoutCommand = buildCommandForConfigKey("keymapLayout");
5657
const customThemeCommand = buildCommandForConfigKey("customTheme");
5758
const adsCommand = buildCommandForConfigKey("ads");
@@ -216,6 +217,7 @@ export const commands: CommandsSubgroup = {
216217
"showOutOfFocusWarning",
217218
"capsLockWarning",
218219
showAverageCommand,
220+
showPbCommand,
219221
"monkeyPowerLevel",
220222
"monkey"
221223
),
@@ -377,6 +379,7 @@ const lists = {
377379
lazyMode: lazyModeCommand.subgroup,
378380
paceCaretMode: paceCaretCommand.subgroup,
379381
showAverage: showAverageCommand.subgroup,
382+
showPb: showPbCommand.subgroup,
380383
minWpm: minSpeedCommand.subgroup,
381384
minAcc: minAccCommand.subgroup,
382385
minBurst: MinBurstCommands[0]?.subgroup,

frontend/src/ts/config-metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ export const configMetadata: ConfigMetadataObject = {
742742
displayString: "show average",
743743
changeRequiresRestart: false,
744744
},
745+
showPb: {
746+
icon: "fa-crown",
747+
displayString: "show personal best",
748+
changeRequiresRestart: false,
749+
},
745750

746751
// other (hidden)
747752
accountChart: {

frontend/src/ts/constants/default-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const obj: Config = {
9797
britishEnglish: false,
9898
lazyMode: false,
9999
showAverage: "off",
100+
showPb: false,
100101
tapeMode: "off",
101102
tapeMargin: 50,
102103
maxLineWidth: 0,

frontend/src/ts/elements/modes-notice.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { isAuthenticated } from "../firebase";
99
import * as CustomTextState from "../states/custom-text-name";
1010
import { getLanguageDisplayString } from "../utils/strings";
1111
import Format from "../utils/format";
12-
import { getActiveFunboxNames } from "../test/funbox/list";
13-
import { escapeHTML } from "../utils/misc";
12+
import { getActiveFunboxes, getActiveFunboxNames } from "../test/funbox/list";
13+
import { escapeHTML, getMode2 } from "../utils/misc";
1414

1515
ConfigEvent.subscribe((eventKey) => {
1616
const configKeys: ConfigEvent.ConfigEventKey[] = [
@@ -26,6 +26,7 @@ ConfigEvent.subscribe((eventKey) => {
2626
"confidenceMode",
2727
"layout",
2828
"showAverage",
29+
"showPb",
2930
"typingSpeedUnit",
3031
"quickRestart",
3132
"customPolyglot",
@@ -191,6 +192,36 @@ export async function update(): Promise<void> {
191192
}
192193
}
193194

195+
if (Config.showPb) {
196+
if (!isAuthenticated()) {
197+
return;
198+
}
199+
const mode2 = getMode2(Config, TestWords.currentQuote);
200+
const pb = await DB.getLocalPB(
201+
Config.mode,
202+
mode2,
203+
Config.punctuation,
204+
Config.numbers,
205+
Config.language,
206+
Config.difficulty,
207+
Config.lazyMode,
208+
getActiveFunboxes()
209+
);
210+
211+
let str = "no pb";
212+
213+
if (pb !== undefined) {
214+
str = `${Format.typingSpeed(pb.wpm, {
215+
showDecimalPlaces: true,
216+
suffix: ` ${Config.typingSpeedUnit}`,
217+
})} ${pb?.acc}% acc`;
218+
}
219+
220+
$(".pageTest #testModesNotice").append(
221+
`<button class="textButton" commands="showPb"><i class="fas fa-crown"></i>${str}</button>`
222+
);
223+
}
224+
194225
if (Config.minWpm !== "off") {
195226
$(".pageTest #testModesNotice").append(
196227
`<button class="textButton" commands="minWpm"><i class="fas fa-bomb"></i>min ${Format.typingSpeed(
@@ -277,15 +308,3 @@ export async function update(): Promise<void> {
277308
}
278309
} catch {}
279310
}
280-
281-
if (import.meta.hot !== undefined) {
282-
import.meta.hot.dispose(() => {
283-
//
284-
});
285-
import.meta.hot.accept(() => {
286-
//
287-
});
288-
import.meta.hot.on("vite:afterUpdate", () => {
289-
void update();
290-
});
291-
}

packages/schemas/src/configs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ export type MinimumBurst = z.infer<typeof MinimumBurstSchema>;
229229
export const ShowAverageSchema = z.enum(["off", "speed", "acc", "both"]);
230230
export type ShowAverage = z.infer<typeof ShowAverageSchema>;
231231

232+
export const ShowPbSchema = z.boolean();
233+
export type ShowPb = z.infer<typeof ShowPbSchema>;
234+
232235
export const ColorHexValueSchema = z.string().regex(/^#([\da-f]{3}){1,2}$/i);
233236
export type ColorHexValue = z.infer<typeof ColorHexValueSchema>;
234237

@@ -461,6 +464,7 @@ export const ConfigSchema = z
461464
showOutOfFocusWarning: z.boolean(),
462465
capsLockWarning: z.boolean(),
463466
showAverage: ShowAverageSchema,
467+
showPb: ShowPbSchema,
464468

465469
// other (hidden)
466470
accountChart: AccountChartSchema,
@@ -596,6 +600,7 @@ export const ConfigGroupsLiteral = {
596600
showOutOfFocusWarning: "hideElements",
597601
capsLockWarning: "hideElements",
598602
showAverage: "hideElements",
603+
showPb: "hideElements",
599604

600605
//other
601606
accountChart: "hidden",

0 commit comments

Comments
 (0)