Stop the timer properly when the user finishes typing

This commit is contained in:
2025-02-17 20:22:46 +01:00
parent 9db48e6940
commit b6c7edecfd
+2 -6
View File
@@ -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;