2021-02-07 04:38:58 +01:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import LogTable from '../components/log-table';
|
2020-10-30 02:01:38 +01:00
|
|
|
|
2021-02-07 04:38:58 +01:00
|
|
|
import { LOGS_ALL, fetchData } from '../utils/apis';
|
2020-10-30 02:01:38 +01:00
|
|
|
|
|
|
|
const FETCH_INTERVAL = 5 * 1000; // 5 sec
|
|
|
|
|
|
|
|
export default function Logs() {
|
|
|
|
const [logs, setLogs] = useState([]);
|
|
|
|
|
|
|
|
const getInfo = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(LOGS_ALL);
|
|
|
|
setLogs(result);
|
|
|
|
} catch (error) {
|
2021-02-07 04:38:58 +01:00
|
|
|
console.log('==== error', error);
|
2020-10-30 02:01:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let getStatusIntervalId = null;
|
|
|
|
|
|
|
|
setInterval(getInfo, FETCH_INTERVAL);
|
|
|
|
getInfo();
|
|
|
|
|
|
|
|
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
|
|
|
|
// returned function will be called on component unmount
|
|
|
|
return () => {
|
|
|
|
clearInterval(getStatusIntervalId);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
2021-02-07 04:38:58 +01:00
|
|
|
return <LogTable logs={logs} pageSize={20} />;
|
2020-10-30 02:01:38 +01:00
|
|
|
}
|