Skip to content

Commit

Permalink
fix: show average showing decimals even if decimals are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Oct 11, 2023
1 parent 8852c59 commit 5a2250c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion frontend/src/ts/elements/modes-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export async function update(): Promise<void> {
if (Auth?.currentUser && avgWPM > 0) {
const avgWPMText = ["speed", "both"].includes(Config.showAverage)
? getTypingSpeedUnit(Config.typingSpeedUnit).convertWithUnitSuffix(
avgWPM
avgWPM,
Config.alwaysShowDecimalPlaces
)
: "";

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/ts/test/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ function updateWpmAndAcc(): void {
);
} else {
//not showing decimal places
let wpmHover = typingSpeedUnit.convertWithUnitSuffix(result.wpm);
let rawWpmHover = typingSpeedUnit.convertWithUnitSuffix(result.rawWpm);
let wpmHover = typingSpeedUnit.convertWithUnitSuffix(result.wpm, true);
let rawWpmHover = typingSpeedUnit.convertWithUnitSuffix(
result.rawWpm,
true
);
if (Config.typingSpeedUnit != "wpm") {
wpmHover += " (" + result.wpm.toFixed(2) + " wpm)";
rawWpmHover += " (" + result.rawWpm.toFixed(2) + " wpm)";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ declare namespace MonkeyTypes {
interface TypingSpeedUnitSettings {
fromWpm: (number) => number;
toWpm: (number) => number;
convertWithUnitSuffix: (number) => string;
convertWithUnitSuffix: (number, boolean) => string;
fullUnitString: string;
histogramDataBucketSize: number;
historyStepSize: number;
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/ts/utils/typing-speed-units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ class Unit implements MonkeyTypes.TypingSpeedUnitSettings {
return val / this.convertFactor;
}

convertWithUnitSuffix(wpm: number): string {
return roundTo2(this.fromWpm(wpm)).toFixed(2) + " " + this.unit;
convertWithUnitSuffix(wpm: number, withDecimals: boolean): string {
if (withDecimals) {
return roundTo2(this.fromWpm(wpm)).toFixed(2) + " " + this.unit;
} else {
return Math.round(this.fromWpm(wpm)) + " " + this.unit;
}
}
}

Expand Down

0 comments on commit 5a2250c

Please sign in to comment.