From 3a2588f8b57ac83f5599a68029398a5e33ce173c Mon Sep 17 00:00:00 2001
From: Aymeric Chaumont <aymeric.chaumont@student-cs.fr>
Date: Thu, 21 Jul 2022 16:56:33 +0200
Subject: [PATCH] allowed to send comment after having pressed the enter key

---
 frontend/src/components/Comments.js | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/frontend/src/components/Comments.js b/frontend/src/components/Comments.js
index 09f7589..0d7b168 100644
--- a/frontend/src/components/Comments.js
+++ b/frontend/src/components/Comments.js
@@ -138,7 +138,11 @@ export default function Messages({ place, infos, lastMessage, admin }) {
       let new_message = JSON.parse(lastMessage.data);
       if (new_message.type == "news" && infos) {
         setMessages((old_messages) => [new_message.comment, ...old_messages]);
-      } else if (!infos && new_message.type == "comment" && new_message.comment.username != user) {
+      } else if (
+        !infos &&
+        new_message.type == "comment" &&
+        new_message.comment.username != user.name
+      ) {
         setMessages((old_messages) => [...old_messages, new_message.comment]);
       }
     }
@@ -208,6 +212,12 @@ export default function Messages({ place, infos, lastMessage, admin }) {
             value={newComment}
             onChange={(ev) => updateValue(ev.target.value)}
             placeholder="Ajouter un commentaire"
+            onKeyDown={(ev) => {
+              if (ev.key === "Enter" && ev.shiftKey == false) {
+                ev.preventDefault();
+                Submit(ev);
+              }
+            }}
           />
           <button className="comment-input-button" onClick={Submit}>
             <BiSend />
-- 
GitLab