From 032844d023e4141c93d64501465f3d7ac28825c5 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 23 Nov 2025 19:30:30 +0100 Subject: [PATCH] feat: add show personal best you can now view the pb for current test settings right above the test words, before starting the test --- .../ts/commandline/commandline-metadata.ts | 6 +++ frontend/src/ts/commandline/lists.ts | 3 ++ frontend/src/ts/config-metadata.ts | 5 ++ frontend/src/ts/constants/default-config.ts | 1 + frontend/src/ts/elements/modes-notice.ts | 47 +++++++++++++------ packages/schemas/src/configs.ts | 5 ++ 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/frontend/src/ts/commandline/commandline-metadata.ts b/frontend/src/ts/commandline/commandline-metadata.ts index fb105f009..4d2d2ebb1 100644 --- a/frontend/src/ts/commandline/commandline-metadata.ts +++ b/frontend/src/ts/commandline/commandline-metadata.ts @@ -703,6 +703,12 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = { options: "fromSchema", }, }, + showPb: { + subgroup: { + options: "fromSchema", + }, + alias: "pb", + }, monkeyPowerLevel: { alias: "powermode", isVisible: false, diff --git a/frontend/src/ts/commandline/lists.ts b/frontend/src/ts/commandline/lists.ts index 1dbe01c36..5cc8b6174 100644 --- a/frontend/src/ts/commandline/lists.ts +++ b/frontend/src/ts/commandline/lists.ts @@ -52,6 +52,7 @@ const confidenceModeCommand = buildCommandForConfigKey("confidenceMode"); const lazyModeCommand = buildCommandForConfigKey("lazyMode"); const layoutCommand = buildCommandForConfigKey("layout"); const showAverageCommand = buildCommandForConfigKey("showAverage"); +const showPbCommand = buildCommandForConfigKey("showPb"); const keymapLayoutCommand = buildCommandForConfigKey("keymapLayout"); const customThemeCommand = buildCommandForConfigKey("customTheme"); const adsCommand = buildCommandForConfigKey("ads"); @@ -216,6 +217,7 @@ export const commands: CommandsSubgroup = { "showOutOfFocusWarning", "capsLockWarning", showAverageCommand, + showPbCommand, "monkeyPowerLevel", "monkey" ), @@ -377,6 +379,7 @@ const lists = { lazyMode: lazyModeCommand.subgroup, paceCaretMode: paceCaretCommand.subgroup, showAverage: showAverageCommand.subgroup, + showPb: showPbCommand.subgroup, minWpm: minSpeedCommand.subgroup, minAcc: minAccCommand.subgroup, minBurst: MinBurstCommands[0]?.subgroup, diff --git a/frontend/src/ts/config-metadata.ts b/frontend/src/ts/config-metadata.ts index 7dc8726e8..62650b386 100644 --- a/frontend/src/ts/config-metadata.ts +++ b/frontend/src/ts/config-metadata.ts @@ -742,6 +742,11 @@ export const configMetadata: ConfigMetadataObject = { displayString: "show average", changeRequiresRestart: false, }, + showPb: { + icon: "fa-crown", + displayString: "show personal best", + changeRequiresRestart: false, + }, // other (hidden) accountChart: { diff --git a/frontend/src/ts/constants/default-config.ts b/frontend/src/ts/constants/default-config.ts index fa08f54bc..0fb967fb5 100644 --- a/frontend/src/ts/constants/default-config.ts +++ b/frontend/src/ts/constants/default-config.ts @@ -97,6 +97,7 @@ const obj: Config = { britishEnglish: false, lazyMode: false, showAverage: "off", + showPb: false, tapeMode: "off", tapeMargin: 50, maxLineWidth: 0, diff --git a/frontend/src/ts/elements/modes-notice.ts b/frontend/src/ts/elements/modes-notice.ts index aa2888565..43c708eca 100644 --- a/frontend/src/ts/elements/modes-notice.ts +++ b/frontend/src/ts/elements/modes-notice.ts @@ -9,8 +9,8 @@ import { isAuthenticated } from "../firebase"; import * as CustomTextState from "../states/custom-text-name"; import { getLanguageDisplayString } from "../utils/strings"; import Format from "../utils/format"; -import { getActiveFunboxNames } from "../test/funbox/list"; -import { escapeHTML } from "../utils/misc"; +import { getActiveFunboxes, getActiveFunboxNames } from "../test/funbox/list"; +import { escapeHTML, getMode2 } from "../utils/misc"; ConfigEvent.subscribe((eventKey) => { const configKeys: ConfigEvent.ConfigEventKey[] = [ @@ -26,6 +26,7 @@ ConfigEvent.subscribe((eventKey) => { "confidenceMode", "layout", "showAverage", + "showPb", "typingSpeedUnit", "quickRestart", "customPolyglot", @@ -191,6 +192,36 @@ export async function update(): Promise { } } + if (Config.showPb) { + if (!isAuthenticated()) { + return; + } + const mode2 = getMode2(Config, TestWords.currentQuote); + const pb = await DB.getLocalPB( + Config.mode, + mode2, + Config.punctuation, + Config.numbers, + Config.language, + Config.difficulty, + Config.lazyMode, + getActiveFunboxes() + ); + + let str = "no pb"; + + if (pb !== undefined) { + str = `${Format.typingSpeed(pb.wpm, { + showDecimalPlaces: true, + suffix: ` ${Config.typingSpeedUnit}`, + })} ${pb?.acc}% acc`; + } + + $(".pageTest #testModesNotice").append( + `` + ); + } + if (Config.minWpm !== "off") { $(".pageTest #testModesNotice").append( `