console fix

This commit is contained in:
AntoninoP 2024-08-18 18:55:22 +02:00
parent 3e329d5bb3
commit e25dcbcf6a

View File

@ -19,29 +19,33 @@ const ServerConsole = ({ user }) => {
logsEndRef.current?.scrollIntoView({ behavior: "smooth" }); logsEndRef.current?.scrollIntoView({ behavior: "smooth" });
}; };
useEffect(() => { const fetchServerLogs = async () => {
const fetchServerLogs = async () => { setLoading(true);
setLoading(true); setError(null);
setError(null);
try { try {
const response = await serviiApi.fetchLogs(serverName); const response = await serviiApi.fetchLogs(serverName);
if (response.return_code === 200) { if (response.return_code === 200) {
let logString = response.message; let logString = response.message;
logString = logString.slice(1, -1); logString = logString.slice(1, -1);
logString = logString.replace(/\\n/g, '\n'); logString = logString.replace(/\\n/g, '\n');
logString = logString.replace(/\\\"/g, '"'); logString = logString.replace(/\\\"/g, '"');
setLogs(logString); logString = logString.replace(/, ?/g, '');
} else { logString = logString.replace(/"{2,}/g, '');
setError(`Erreur lors de la récupération des logs: ${response.message}`); logString = logString.replace(/'{2,}/g, '');
} logString = logString.trim();
} catch (err) { setLogs(logString);
setError(`Erreur: ${err.message}`); } else {
} finally { setError(`Erreur lors de la récupération des logs: ${response.message}`);
setLoading(false);
} }
}; } catch (err) {
setError(`Erreur: ${err.message}`);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchServerLogs(); fetchServerLogs();
}, [serverName]); }, [serverName]);
@ -53,6 +57,7 @@ const ServerConsole = ({ user }) => {
if (message.trim()) { if (message.trim()) {
console.log(`Message envoyé: ${message}`); console.log(`Message envoyé: ${message}`);
setMessage(''); setMessage('');
fetchServerLogs();
} }
}; };
@ -81,7 +86,6 @@ const ServerConsole = ({ user }) => {
</pre> </pre>
<div ref={logsEndRef} /> <div ref={logsEndRef} />
</div> </div>
{}
<div className={styles.chatInputContainer}> <div className={styles.chatInputContainer}>
<input <input
type="text" type="text"