diff --git a/src/pages/ServerHistory/ServerHistory.jsx b/src/pages/ServerHistory/ServerHistory.jsx index 50ebb63..ec083e6 100644 --- a/src/pages/ServerHistory/ServerHistory.jsx +++ b/src/pages/ServerHistory/ServerHistory.jsx @@ -23,7 +23,7 @@ const ServerHistory = () => { const fetchServerHistory = async () => { setError(null); setLoading(true); - + try { const response = await serviiApi.fetchHistory(serverName); if (response.return_code === 200) { @@ -35,26 +35,31 @@ const ServerHistory = () => { historyString = historyString.replace(/"{2,}/g, ''); historyString = historyString.replace(/'{2,}/g, ''); historyString = historyString.trim(); - + historyString = historyString.replace(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(type": ")/g, '$1", "$2'); historyString = historyString.replace(/(type": "ServerCreate|ServerRun|Command|UpdateProperties)(details": )/g, '$1", "$2'); - + const historyArray = historyString.split('\n').map(entry => { const timestampMatch = entry.match(/"timestamp": "(.*?)"/); const typeMatch = entry.match(/"type": "(.*?)"/); const detailsMatch = entry.match(/"details": "(.*?)"/); - + const parsedEntry = { timestamp: timestampMatch ? timestampMatch[1] : "Unknown", type: typeMatch ? typeMatch[1] : "Unknown", details: detailsMatch ? detailsMatch[1] : null }; - + return parsedEntry; }); - - - setHistory(historyArray); + + const sortedHistoryArray = historyArray.sort((a, b) => { + const dateA = new Date(a.timestamp); + const dateB = new Date(b.timestamp); + return dateB - dateA; + }); + + setHistory(sortedHistoryArray); } else { console.error("Failed to fetch history, response:", response); } @@ -65,6 +70,7 @@ const ServerHistory = () => { setLoading(false); } }; + useEffect(() => { fetchServerHistory();