mirror of
https://github.com/hazemKrimi/touch-programming.git
synced 2026-05-02 02:30:26 +00:00
Stop the timer properly when the user finishes typing
This commit is contained in:
@@ -13,7 +13,7 @@ type CodeProps = {
|
|||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Code({code, loaded}: CodeProps) {
|
function Code({ code, loaded }: CodeProps) {
|
||||||
const {
|
const {
|
||||||
startedTyping,
|
startedTyping,
|
||||||
characters,
|
characters,
|
||||||
@@ -30,13 +30,7 @@ function Code({code, loaded}: CodeProps) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (!loaded) return;
|
if (!loaded) return;
|
||||||
if (characters.length === code.length) {
|
|
||||||
setStartedTyping(false);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (KEYS_TO_DISABLE.includes(event.key)) return;
|
if (KEYS_TO_DISABLE.includes(event.key)) return;
|
||||||
|
|
||||||
if (!startedTyping) setStartedTyping(true);
|
if (!startedTyping) setStartedTyping(true);
|
||||||
|
|
||||||
const char = code[characters.length];
|
const char = code[characters.length];
|
||||||
@@ -65,6 +59,8 @@ function Code({code, loaded}: CodeProps) {
|
|||||||
}, [loaded, characters]);
|
}, [loaded, characters]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (characters.length === code.length) setStartedTyping(false);
|
||||||
|
|
||||||
const typed = characters.filter(char => char !== 'space').length;
|
const typed = characters.filter(char => char !== 'space').length;
|
||||||
const correctlyTyped = characters.filter(char => char && char !== 'space').length;
|
const correctlyTyped = characters.filter(char => char && char !== 'space').length;
|
||||||
const incorrectlyTyped = characters.filter(char => !char).length;
|
const incorrectlyTyped = characters.filter(char => !char).length;
|
||||||
|
|||||||
Reference in New Issue
Block a user