From b9881d10edece06731622586244d4571c1d19955 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Tue, 27 Feb 2024 11:19:42 +0100 Subject: [PATCH 1/2] fix: fix tags personal bests handling of missing numbers flag --- frontend/src/ts/db.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index e5a108abdc1f..1ea22fe7e8c5 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -273,6 +273,7 @@ export async function getUserResults(offset?: number): Promise { } if (result.numbers === undefined) result.numbers = false; if (result.punctuation === undefined) result.punctuation = false; + if (result.numbers === undefined) result.numbers = false; if (result.quoteLength === undefined) result.quoteLength = -1; if (result.restartCount === undefined) result.restartCount = 0; if (result.incompleteTestSeconds === undefined) { @@ -742,8 +743,8 @@ export async function getLocalTagPB( ret = personalBests.find( (pb) => - pb.punctuation === punctuation && - pb.numbers === numbers && + (pb.punctuation ?? false) === punctuation && + (pb.numbers ?? false) === numbers && pb.difficulty === difficulty && pb.language === language && (pb.lazyMode === lazyMode || (pb.lazyMode === undefined && !lazyMode)) @@ -797,8 +798,8 @@ export async function saveLocalTagPB( ] as unknown as SharedTypes.PersonalBest[] ).forEach((pb) => { if ( - pb.punctuation === punctuation && - pb.numbers === numbers && + (pb.punctuation ?? false) === punctuation && + (pb.numbers ?? false) === numbers && pb.difficulty === difficulty && pb.language === language && (pb.lazyMode === lazyMode || (pb.lazyMode === undefined && !lazyMode)) From 3453f46b1b3f7f1caad3a35dc879f8000363df61 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Tue, 27 Feb 2024 11:27:12 +0100 Subject: [PATCH 2/2] add missing filters for numbers flag --- frontend/src/ts/db.ts | 42 +++------------------ frontend/src/ts/elements/last-10-average.ts | 1 + frontend/src/ts/test/pace-caret.ts | 2 + 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index 1ea22fe7e8c5..5c048c27565b 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -404,44 +404,11 @@ export async function deleteCustomTheme(themeId: string): Promise { return true; } -async function _getUserHighestWpm( - mode: M, - mode2: SharedTypes.Config.Mode2, - punctuation: boolean, - language: string, - difficulty: SharedTypes.Config.Difficulty, - lazyMode: boolean -): Promise { - function cont(): number { - let topWpm = 0; - - dbSnapshot?.results?.forEach((result) => { - if ( - result.mode === mode && - `${result.mode2}` === `${mode2 as string | number}` && //using template strings here because legacy results can have numbers in mode2 - result.punctuation === punctuation && - result.language === language && - result.difficulty === difficulty && - (result.lazyMode === lazyMode || - (result.lazyMode === undefined && !lazyMode)) - ) { - if (result.wpm > topWpm) { - topWpm = result.wpm; - } - } - }); - return topWpm; - } - - const retval = !dbSnapshot || dbSnapshot.results === undefined ? 0 : cont(); - - return retval; -} - export async function getUserAverage10( mode: M, mode2: SharedTypes.Config.Mode2, punctuation: boolean, + numbers: boolean, language: string, difficulty: SharedTypes.Config.Difficulty, lazyMode: boolean @@ -469,7 +436,8 @@ export async function getUserAverage10( for (const result of snapshot.results) { if ( result.mode === mode && - result.punctuation === punctuation && + (result.punctuation ?? false) === punctuation && + (result.numbers ?? false) === numbers && result.language === language && result.difficulty === difficulty && (result.lazyMode === lazyMode || @@ -525,6 +493,7 @@ export async function getUserDailyBest( mode: M, mode2: SharedTypes.Config.Mode2, punctuation: boolean, + numbers: boolean, language: string, difficulty: SharedTypes.Config.Difficulty, lazyMode: boolean @@ -547,7 +516,8 @@ export async function getUserDailyBest( for (const result of snapshot.results) { if ( result.mode === mode && - result.punctuation === punctuation && + (result.punctuation ?? false) === punctuation && + (result.numbers ?? false) === numbers && result.language === language && result.difficulty === difficulty && (result.lazyMode === lazyMode || diff --git a/frontend/src/ts/elements/last-10-average.ts b/frontend/src/ts/elements/last-10-average.ts index 99519703b89e..658b61f53fdb 100644 --- a/frontend/src/ts/elements/last-10-average.ts +++ b/frontend/src/ts/elements/last-10-average.ts @@ -14,6 +14,7 @@ export async function update(): Promise { Config.mode, mode2 as never, Config.punctuation, + Config.numbers, Config.language, Config.difficulty, Config.lazyMode diff --git a/frontend/src/ts/test/pace-caret.ts b/frontend/src/ts/test/pace-caret.ts index f1a9a22304dc..e04e6a6a468d 100644 --- a/frontend/src/ts/test/pace-caret.ts +++ b/frontend/src/ts/test/pace-caret.ts @@ -80,6 +80,7 @@ export async function init(): Promise { Config.mode, mode2, Config.punctuation, + Config.numbers, Config.language, Config.difficulty, Config.lazyMode @@ -90,6 +91,7 @@ export async function init(): Promise { Config.mode, mode2, Config.punctuation, + Config.numbers, Config.language, Config.difficulty, Config.lazyMode