From 5b41f2440414faea8b727efdf1d922dbbaf06072 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Thu, 27 Feb 2025 23:20:17 -0500 Subject: [PATCH 1/2] Return key submits form Fixes #262 --- client/src/pages/Student/JoinRoom/JoinRoom.tsx | 12 ++++++++++-- client/src/pages/Teacher/Login/Login.tsx | 15 ++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/client/src/pages/Student/JoinRoom/JoinRoom.tsx b/client/src/pages/Student/JoinRoom/JoinRoom.tsx index f0ac8d7..57ecc22 100644 --- a/client/src/pages/Student/JoinRoom/JoinRoom.tsx +++ b/client/src/pages/Student/JoinRoom/JoinRoom.tsx @@ -111,6 +111,12 @@ const JoinRoom: React.FC = () => { webSocketService.submitAnswer(answerData); }; + const handleReturnKey = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleSocket(); + } + }; + if (isWaitingForTeacher) { return (
@@ -167,7 +173,8 @@ const JoinRoom: React.FC = () => { onChange={(e) => setRoomName(e.target.value)} placeholder="Numéro de la salle" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleReturnKey} /> { onChange={(e) => setUsername(e.target.value)} placeholder="Nom d'utilisateur" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleReturnKey} /> { }; + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + login(); + } + }; return ( { onChange={(e) => setEmail(e.target.value)} placeholder="Adresse courriel" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleKeyPress} // Add this line as well /> { onChange={(e) => setPassword(e.target.value)} placeholder="Mot de passe" sx={{ marginBottom: '1rem' }} - fullWidth + fullWidth={true} + onKeyDown={handleKeyPress} // Add this line as well /> Date: Thu, 27 Feb 2025 23:43:58 -0500 Subject: [PATCH 2/2] ignorer touch si champs vide --- client/src/pages/Student/JoinRoom/JoinRoom.tsx | 2 +- client/src/pages/Teacher/Login/Login.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/pages/Student/JoinRoom/JoinRoom.tsx b/client/src/pages/Student/JoinRoom/JoinRoom.tsx index 57ecc22..c458d61 100644 --- a/client/src/pages/Student/JoinRoom/JoinRoom.tsx +++ b/client/src/pages/Student/JoinRoom/JoinRoom.tsx @@ -112,7 +112,7 @@ const JoinRoom: React.FC = () => { }; const handleReturnKey = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { + if (e.key === 'Enter' && username && roomName) { handleSocket(); } }; diff --git a/client/src/pages/Teacher/Login/Login.tsx b/client/src/pages/Teacher/Login/Login.tsx index c96f3b8..f305101 100644 --- a/client/src/pages/Teacher/Login/Login.tsx +++ b/client/src/pages/Teacher/Login/Login.tsx @@ -36,8 +36,8 @@ const Login: React.FC = () => { }; - const handleKeyPress = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { + const handleReturnKey = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && email && password) { login(); } }; @@ -55,7 +55,7 @@ const Login: React.FC = () => { placeholder="Adresse courriel" sx={{ marginBottom: '1rem' }} fullWidth={true} - onKeyDown={handleKeyPress} // Add this line as well + onKeyDown={handleReturnKey} // Add this line as well /> { placeholder="Mot de passe" sx={{ marginBottom: '1rem' }} fullWidth={true} - onKeyDown={handleKeyPress} // Add this line as well + onKeyDown={handleReturnKey} // Add this line as well />