mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-10 05:35:05 +08:00
fixed showavg duplication
This commit is contained in:
parent
725e51e9a5
commit
251b7234a4
3 changed files with 31 additions and 14 deletions
25
frontend/src/scripts/elements/last-10-average.ts
Normal file
25
frontend/src/scripts/elements/last-10-average.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import * as DB from "../db";
|
||||
import * as Misc from "../misc";
|
||||
import Config from "../config";
|
||||
import * as TestWords from "../test/test-words";
|
||||
|
||||
let value = 0;
|
||||
|
||||
export async function update(): Promise<void> {
|
||||
const mode2 = Misc.getMode2(Config, TestWords.randomQuote);
|
||||
let wpm = await DB.getUserAverageWpm10(
|
||||
Config.mode,
|
||||
mode2 as never,
|
||||
Config.punctuation,
|
||||
Config.language,
|
||||
Config.difficulty,
|
||||
Config.lazyMode
|
||||
);
|
||||
wpm = Misc.roundTo2(wpm);
|
||||
if (!Config.alwaysShowDecimalPlaces) wpm = Math.round(wpm);
|
||||
value = wpm;
|
||||
}
|
||||
|
||||
export function get(): number {
|
||||
return value;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import * as PaceCaret from "../test/pace-caret";
|
||||
import * as TestState from "../test/test-state";
|
||||
import * as DB from "../db";
|
||||
import * as Misc from "../misc";
|
||||
import * as Last10Average from "../elements/last-10-average";
|
||||
import Config from "../config";
|
||||
import * as TestWords from "../test/test-words";
|
||||
import * as ConfigEvent from "../observables/config-event";
|
||||
|
@ -107,20 +107,10 @@ export async function update(): Promise<void> {
|
|||
}
|
||||
|
||||
if (Config.showAvg) {
|
||||
const mode2 = Misc.getMode2(Config, TestWords.randomQuote);
|
||||
let wpm = await DB.getUserAverageWpm10(
|
||||
Config.mode,
|
||||
mode2 as never,
|
||||
Config.punctuation,
|
||||
Config.language,
|
||||
Config.difficulty,
|
||||
Config.lazyMode
|
||||
);
|
||||
wpm = Math.round(wpm * 100) / 100;
|
||||
if (!Config.alwaysShowDecimalPlaces) wpm = Math.round(wpm);
|
||||
if (wpm > 0) {
|
||||
const val = Last10Average.get();
|
||||
if (firebase.auth().currentUser && val > 0) {
|
||||
$(".pageTest #testModesNotice").append(
|
||||
`<div class="text-button" commands="commandsShowAvg"><i class="fas fa-tachometer-alt"></i>avg: ${wpm}wpm</div>`
|
||||
`<div class="text-button" commands="commandsShowAvg"><i class="fas fa-tachometer-alt"></i>avg: ${val}wpm</div>`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import * as ModesNotice from "../elements/modes-notice";
|
|||
import * as PageTransition from "../states/page-transition";
|
||||
import * as ConfigEvent from "../observables/config-event";
|
||||
import * as TimerEvent from "../observables/timer-event";
|
||||
import * as Last10Average from "../elements/last-10-average";
|
||||
|
||||
const objecthash = require("node-object-hash")().hash;
|
||||
|
||||
|
@ -372,6 +373,7 @@ export function restart(
|
|||
Replay.pauseReplay();
|
||||
TestInput.setBailout(false);
|
||||
PaceCaret.reset();
|
||||
if (Config.showAvg) Last10Average.update();
|
||||
$("#showWordHistoryButton").removeClass("loaded");
|
||||
$("#restartTestButton").blur();
|
||||
Funbox.resetMemoryTimer();
|
||||
|
|
Loading…
Reference in a new issue