From e25dcbcf6af425edfd1e2fe498d5ba20bab14c4b Mon Sep 17 00:00:00 2001 From: AntoninoP Date: Sun, 18 Aug 2024 18:55:22 +0200 Subject: [PATCH] console fix --- src/pages/ServerConsole/ServerConsole.jsx | 46 ++++++++++++----------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/pages/ServerConsole/ServerConsole.jsx b/src/pages/ServerConsole/ServerConsole.jsx index a658bb9..b782339 100644 --- a/src/pages/ServerConsole/ServerConsole.jsx +++ b/src/pages/ServerConsole/ServerConsole.jsx @@ -19,29 +19,33 @@ const ServerConsole = ({ user }) => { logsEndRef.current?.scrollIntoView({ behavior: "smooth" }); }; - useEffect(() => { - const fetchServerLogs = async () => { - setLoading(true); - setError(null); + const fetchServerLogs = async () => { + setLoading(true); + setError(null); - try { - const response = await serviiApi.fetchLogs(serverName); - if (response.return_code === 200) { - let logString = response.message; - logString = logString.slice(1, -1); - logString = logString.replace(/\\n/g, '\n'); - logString = logString.replace(/\\\"/g, '"'); - setLogs(logString); - } else { - setError(`Erreur lors de la récupération des logs: ${response.message}`); - } - } catch (err) { - setError(`Erreur: ${err.message}`); - } finally { - setLoading(false); + try { + const response = await serviiApi.fetchLogs(serverName); + if (response.return_code === 200) { + let logString = response.message; + logString = logString.slice(1, -1); + logString = logString.replace(/\\n/g, '\n'); + logString = logString.replace(/\\\"/g, '"'); + logString = logString.replace(/, ?/g, ''); + logString = logString.replace(/"{2,}/g, ''); + logString = logString.replace(/'{2,}/g, ''); + logString = logString.trim(); + setLogs(logString); + } else { + setError(`Erreur lors de la récupération des logs: ${response.message}`); } - }; + } catch (err) { + setError(`Erreur: ${err.message}`); + } finally { + setLoading(false); + } + }; + useEffect(() => { fetchServerLogs(); }, [serverName]); @@ -53,6 +57,7 @@ const ServerConsole = ({ user }) => { if (message.trim()) { console.log(`Message envoyé: ${message}`); setMessage(''); + fetchServerLogs(); } }; @@ -81,7 +86,6 @@ const ServerConsole = ({ user }) => {
- {}