From b6c7edecfd287f1dd9c0f491fc6bcc5d56c83935 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Mon, 17 Feb 2025 20:22:46 +0100 Subject: [PATCH] Stop the timer properly when the user finishes typing --- client/src/components/Code/index.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/src/components/Code/index.tsx b/client/src/components/Code/index.tsx index 5e496dc..2b219bc 100644 --- a/client/src/components/Code/index.tsx +++ b/client/src/components/Code/index.tsx @@ -13,7 +13,7 @@ type CodeProps = { loaded: boolean; } -function Code({code, loaded}: CodeProps) { +function Code({ code, loaded }: CodeProps) { const { startedTyping, characters, @@ -30,13 +30,7 @@ function Code({code, loaded}: CodeProps) { event.preventDefault(); if (!loaded) return; - if (characters.length === code.length) { - setStartedTyping(false); - - return; - } if (KEYS_TO_DISABLE.includes(event.key)) return; - if (!startedTyping) setStartedTyping(true); const char = code[characters.length]; @@ -65,6 +59,8 @@ function Code({code, loaded}: CodeProps) { }, [loaded, characters]); useEffect(() => { + if (characters.length === code.length) setStartedTyping(false); + const typed = characters.filter(char => char !== 'space').length; const correctlyTyped = characters.filter(char => char && char !== 'space').length; const incorrectlyTyped = characters.filter(char => !char).length;