From 91494fb9e36c063e41ea68af427190d79301ad84 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Tue, 27 Feb 2024 20:20:30 +0100 Subject: [PATCH] fix: fix tags personal bests handling of missing numbers flag (fehmer) (#5146) * fix: fix tags personal bests handling of missing numbers flag * add missing filters for numbers flag --- frontend/src/ts/db.ts | 51 +++++---------------- frontend/src/ts/elements/last-10-average.ts | 1 + frontend/src/ts/test/pace-caret.ts | 2 + 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index e5a108abdc1f..5c048c27565b 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) { @@ -403,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 @@ -468,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 || @@ -524,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 @@ -546,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 || @@ -742,8 +713,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 +768,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)) 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