Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat: timer stops at the end of text
Browse files Browse the repository at this point in the history
  • Loading branch information
vycdev committed Feb 23, 2020
1 parent 0f93eb5 commit a9558bf
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/web/src/components/typingBox/typingBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let CPM = 0
let WPM = 0

const getText = () => {
return "like idea until certain always busy so music best self is world dont sentence world next river like idea until certain always busy so music best self is world dont sentence world next river like idea until certain always busy so music best self is world dont sentence world next river "
return "like idea until certain always busy so music best self is world dont"
}

const checkBackspaceReturn = (e: any) => {
Expand Down Expand Up @@ -73,10 +73,10 @@ const buildTextComponentsArray = (text: string, elColor: string) => {
<LetterElement
key={`${i}letter`}
style={{
color:
string.length > word.length
? "red"
: elColor
color: elColor
// string.length > word.length
// ? "red"
// : elColor
}}
>
<u>{letter}</u>
Expand Down Expand Up @@ -137,7 +137,6 @@ const getTextToBeCompared = (text: string) => {
const checkAndIncrement = () => {
if (string === getTextToBeCompared(getText())[increment]) {
increment++
if (increment >= getTextToBeCompared(getText()).length) increment = 0
charTyped += string.length + 1
correctedCharTyped += string.length + 1
color = "green"
Expand Down Expand Up @@ -211,7 +210,13 @@ export const Box = () => {

useEffect(() => {
setTimeout(() => {
setTime(time === 0 ? 0 : CPM === -1 && cpm === 0 ? 60 : time - 1)
setTime(
time === 0 || increment >= getTextToBeCompared(getText()).length
? 0
: CPM === -1 && cpm === 0
? 60
: time - 1
)
setCpm(calculateCpmWpm()[0])
setWpm(calculateCpmWpm()[1])
}, 1000)
Expand Down

0 comments on commit a9558bf

Please sign in to comment.