Skip to content

Commit c9fa677

Browse files
committed
yeet missed words
1 parent 297775f commit c9fa677

6 files changed

Lines changed: 35 additions & 28 deletions

File tree

frontend/src/ts/input/handlers/insert-text.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
164164
// general per keypress updates
165165
Replay.addReplayEvent(correct ? "correctLetter" : "incorrectLetter", data);
166166
WeakSpot.updateScore(data, correct);
167-
if (!correct) {
168-
TestInput.pushMissedWord(TestWords.words.getCurrentText());
169-
}
170167
if (Config.keymapMode === "react") {
171168
flash(data, correct);
172169
}

frontend/src/ts/test/events/stats.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,29 @@ export function forceReleaseAllKeys(): void {
753753
}
754754
}
755755

756+
export function getMissedWords(): Record<string, number> {
757+
const events = getAllTestEvents();
758+
759+
const missedWords: Record<string, number> = {};
760+
761+
for (const event of events) {
762+
if (
763+
event.type === "input" &&
764+
event.data.inputType === "insertText" &&
765+
!event.data.correct
766+
) {
767+
const word = TestWords.words.getText(event.data.wordIndex);
768+
if (missedWords[word] === undefined) {
769+
missedWords[word] = 1;
770+
} else {
771+
missedWords[word]++;
772+
}
773+
}
774+
}
775+
776+
return missedWords;
777+
}
778+
756779
export const __testing = {
757780
getTimerBoundaries,
758781
};

frontend/src/ts/test/practise-words.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { configEvent } from "../events/config";
99
import { setCustomTextName } from "../legacy-states/custom-text-name";
1010
import { Mode } from "@monkeytype/schemas/shared";
1111
import { CustomTextSettings } from "@monkeytype/schemas/results";
12-
import { getBurstHistory } from "./events/stats";
12+
import { getBurstHistory, getMissedWords } from "./events/stats";
1313

1414
type Before = {
1515
mode: Mode | null;
@@ -38,11 +38,13 @@ export function init(
3838
limit = 10;
3939
}
4040

41+
const missedWords = getMissedWords();
42+
4143
// missed word, previous word, count
4244
let sortableMissedWords: [string, number][] = [];
4345
if (missed === "words") {
44-
Object.keys(TestInput.missedWords).forEach((missedWord) => {
45-
const missedWordCount = TestInput.missedWords[missedWord];
46+
Object.keys(missedWords).forEach((missedWord) => {
47+
const missedWordCount = missedWords[missedWord];
4648
if (missedWordCount !== undefined) {
4749
sortableMissedWords.push([missedWord, missedWordCount]);
4850
}
@@ -57,7 +59,7 @@ export function init(
5759
if (missed === "biwords") {
5860
for (let i = 0; i < TestWords.words.length; i++) {
5961
const missedWord = TestWords.words.getText(i);
60-
const missedWordCount = TestInput.missedWords[missedWord];
62+
const missedWordCount = missedWords[missedWord];
6163
if (missedWordCount !== undefined) {
6264
if (i === 0) {
6365
sortableMissedBiwords.push([missedWord, "", missedWordCount]);

frontend/src/ts/test/test-input.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,3 @@ class Corrected {
111111

112112
export const input = new Input();
113113
export const corrected = new Corrected();
114-
115-
type MissedWordsType = Record<string, number>;
116-
// We're using Object.create(null) to make sure that __proto__ won't have any special meaning when it's used to index the missedWords object (so if a user mistypes the word __proto__ it will appear in the practise words test)
117-
export let missedWords: MissedWordsType = Object.create(
118-
null,
119-
) as MissedWordsType;
120-
121-
export function pushMissedWord(word: string): void {
122-
if (!Object.keys(missedWords).includes(word)) {
123-
missedWords[word] = 1;
124-
} else {
125-
(missedWords[word] as number) += 1;
126-
}
127-
}
128-
129-
export function restart(): void {
130-
missedWords = Object.create(null) as MissedWordsType;
131-
}

frontend/src/ts/test/test-logic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ export function restart(options = {} as RestartOptions): void {
318318
resetTestEvents();
319319
TestTimer.clear();
320320
setIsTestInvalid(false);
321-
TestInput.restart();
322321
TestInput.corrected.reset();
323322
ShiftTracker.reset();
324323
AltTracker.reset();

frontend/src/ts/test/test-ui.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ import {
6868
import { getTheme } from "../states/theme";
6969
import { skipBreakdownEvent } from "../states/header";
7070
import { wordsHaveNewline } from "../states/test";
71-
import { getBurstHistory, getCurrentAccuracy } from "./events/stats";
71+
import {
72+
getBurstHistory,
73+
getCurrentAccuracy,
74+
getMissedWords,
75+
} from "./events/stats";
7276

7377
export const updateHintsPositionDebounced = Misc.debounceUntilResolved(
7478
updateHintsPosition,
@@ -1962,7 +1966,7 @@ qs(".pageTest #copyMissedWordsListButton")?.on("click", async () => {
19621966
if (Config.mode === "zen") {
19631967
words = TestInput.input.getHistory().join(" ");
19641968
} else {
1965-
words = Object.keys(TestInput.missedWords ?? {}).join(" ");
1969+
words = (Object.keys(getMissedWords()) ?? {}).join(" ");
19661970
}
19671971
await copyToClipboard(words);
19681972
});

0 commit comments

Comments
 (0)