From 885311f87e1cfeb8fa726a4057274a0c40771a56 Mon Sep 17 00:00:00 2001
From: Antoine Gaudron-desjardins <antoine.gaudrondesjardins@student-cs.fr>
Date: Mon, 18 Jul 2022 14:49:58 +0200
Subject: [PATCH] change news order

---
 frontend/.env.template              | 3 ++-
 frontend/src/components/Comments.js | 7 +++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/frontend/.env.template b/frontend/.env.template
index 4055e48..e936d4f 100644
--- a/frontend/.env.template
+++ b/frontend/.env.template
@@ -1 +1,2 @@
-REACT_APP_BASE_URL_BACK=http://localhost:3001/api
\ No newline at end of file
+REACT_APP_BASE_URL_BACK=http://localhost:3001/api
+REACT_APP_SOCKET_URL=ws://localhost:3001/api
\ No newline at end of file
diff --git a/frontend/src/components/Comments.js b/frontend/src/components/Comments.js
index 1f7975a..a3a1304 100644
--- a/frontend/src/components/Comments.js
+++ b/frontend/src/components/Comments.js
@@ -118,10 +118,9 @@ export default function Messages({ place, infos, lastMessage }) {
   useEffect(() => {
     if (lastMessage?.data) {
       let new_message = JSON.parse(lastMessage.data);
-      if (
-        (new_message.type == "news" && infos) ||
-        (new_message.type == "comment" && !infos && new_message.comment.username != user)
-      ) {
+      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) {
         setMessages((old_messages) => [...old_messages, new_message.comment]);
       }
     }
-- 
GitLab