Skip to content

Commit f108f8a

Browse files
committed
add underline for word errors
1 parent 77c3ce2 commit f108f8a

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

components/InputDisplay.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>
1010
<div>
1111
<template v-for="(word, index) in props.allData" :key="index">
12-
<span v-if="word.index >= props.startDisplayIndex && word.index <= props.startDisplayIndex+40">
12+
<span v-if="word.index >= props.startDisplayIndex && word.index <= props.startDisplayIndex+40" :class="`${word.status === 'error' ? 'underline decoration-red-500 underline-offset-8' : ''}`">
1313
<span
1414
v-for="(char, charIndex) in word.characters"
1515
:key="charIndex"

pages/index.vue

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ function isSpace(e: KeyboardEvent) {
431431
432432
function handleSpace() {
433433
const metadata = currentMetadata.value;
434-
434+
metadata.currentWordMetadata.status = getWordStatus()
435435
insertWord(metadata.currentWord);
436436
pushWordLogs();
437437
currentWordNum.value += 2;
@@ -851,6 +851,7 @@ function setShowResults() {
851851
852852
function handleEndWord() {
853853
const metadata = currentMetadata.value;
854+
metadata.currentWordMetadata.status = getWordStatus()
854855
if (metadata.currentWordMetadata.type === 'word') {
855856
insertWord(metadata.currentWord);
856857
pushWordLogs();
@@ -905,16 +906,6 @@ function pushWordLogs() {
905906
1000
906907
);
907908
}
908-
function getWordStatus(): WordLogStatus {
909-
for (let i = 0; i < wordLength; i++) {
910-
if (
911-
currentMetadata.value.currentWordMetadata
912-
.characters[i].status !== 'correct'
913-
)
914-
return 'error';
915-
}
916-
return 'correct';
917-
}
918909
function getWordWpm(): number {
919910
return parseFloat(
920911
(wordLength / 5 / (duration / 60)).toFixed(2)
@@ -936,6 +927,18 @@ function pushWordLogs() {
936927
}
937928
}
938929
930+
function getWordStatus(): WordLogStatus {
931+
const wordLength = currentMetadata.value.currentWordLength
932+
for (let i = 0; i < wordLength; i++) {
933+
if (
934+
currentMetadata.value.currentWordMetadata
935+
.characters[i].status !== 'correct'
936+
)
937+
return 'error';
938+
}
939+
return 'correct';
940+
}
941+
939942
function insertWord(word: string) {
940943
collectedWords.push(word);
941944
}

types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type WordMetadata = {
6262
index: number;
6363
end_time?: string;
6464
start_time?: string;
65-
status?: CharLogStatus;
65+
status?: WordLogStatus;
6666
duration?: number;
6767
wpm?: number;
6868
};

0 commit comments

Comments
 (0)