fix: PB pace caret is always zero (#5143)

* fix: PB pace caret is always zero

* cleanup
This commit is contained in:
Christian Fehmer 2024-02-26 20:57:09 +01:00 committed by GitHub
parent 76267baf1e
commit 668f2612a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -600,37 +600,24 @@ export async function getLocalPB<M extends SharedTypes.Config.Mode>(
if (!funboxes.every((f) => f.canGetPb)) {
return 0;
}
if (dbSnapshot === null || dbSnapshot?.personalBests === null) return 0;
function cont(): number {
let ret = 0;
try {
if (!dbSnapshot?.personalBests) return ret;
const bestsByMode = dbSnapshot?.personalBests[mode][
mode2
] as SharedTypes.PersonalBest[];
(
dbSnapshot.personalBests[mode][
mode2
] as unknown as SharedTypes.PersonalBest[]
).forEach((pb) => {
if (
pb.punctuation === punctuation &&
pb.numbers === numbers &&
pb.difficulty === difficulty &&
pb.language === language &&
(pb.lazyMode === lazyMode || (pb.lazyMode === undefined && !lazyMode))
) {
ret = pb.wpm;
}
});
if (bestsByMode === undefined) return 0;
return ret;
} catch (e) {
return ret;
}
}
const retval = dbSnapshot === null ? 0 : cont();
return retval;
return (
bestsByMode.find(
(pb) =>
(pb.punctuation ?? false) === punctuation &&
(pb.numbers ?? false) === numbers &&
pb.difficulty === difficulty &&
pb.language === language &&
(pb.lazyMode ?? false) === lazyMode
)?.wpm ?? 0
);
}
export async function saveLocalPB<M extends SharedTypes.Config.Mode>(