Skip to content

Commit

Permalink
fix: PB pace caret is always zero (#5143)
Browse files Browse the repository at this point in the history
* fix: PB pace caret is always zero

* cleanup
  • Loading branch information
fehmer authored Feb 26, 2024
1 parent 76267ba commit 668f261
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions frontend/src/ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down

0 comments on commit 668f261

Please sign in to comment.