mirror of
https://github.com/hubHarmony/servii-frontend.git
synced 2024-11-17 21:40:30 +00:00
sorted history yay
This commit is contained in:
parent
0a0b5a7020
commit
89477505aa
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user