Tranga-Website/Website/modules/Footer.tsx

44 lines
2.1 KiB
TypeScript
Raw Normal View History

import React, {useEffect} from 'react';
import '../styles/footer.css';
import Job from './Job';
2024-10-19 20:06:40 +02:00
import Icon from '@mdi/react';
import { mdiRun, mdiCounter, mdiEyeCheck, mdiTrayFull } from '@mdi/js';
import QueuePopUp from "./QueuePopUp";
2024-10-18 02:10:58 +02:00
2024-10-20 20:12:27 +02:00
export default function Footer({connectedToBackend, apiUri} : {connectedToBackend: boolean, apiUri: string}) {
2024-10-18 19:45:23 +02:00
const [MonitoringJobsCount, setMonitoringJobsCount] = React.useState(0);
const [AllJobsCount, setAllJobsCount] = React.useState(0);
const [RunningJobsCount, setRunningJobsCount] = React.useState(0);
const [StandbyJobsCount, setStandbyJobsCount] = React.useState(0);
const [countUpdateInterval, setCountUpdateInterval] = React.useState<number>();
2024-10-18 19:45:23 +02:00
function UpdateBackendState(){
2024-10-20 20:12:27 +02:00
Job.GetMonitoringJobs(apiUri).then((jobs) => setMonitoringJobsCount(jobs.length));
Job.GetAllJobs(apiUri).then((jobs) => setAllJobsCount(jobs.length));
Job.GetRunningJobs(apiUri).then((jobs) => setRunningJobsCount(jobs.length));
Job.GetStandbyJobs(apiUri).then((jobs) => setStandbyJobsCount(jobs.length));
2024-10-18 19:45:23 +02:00
}
useEffect(() => {
if(connectedToBackend){
UpdateBackendState();
setCountUpdateInterval(setInterval(() => {
UpdateBackendState();
}, 2000));
}else{
clearInterval(countUpdateInterval);
setCountUpdateInterval(undefined);
}
}, [connectedToBackend]);
2024-10-18 19:45:23 +02:00
2024-10-18 02:10:58 +02:00
return (
<footer>
<div className="statusBadge"><Icon path={mdiEyeCheck} size={1}/> <span>{MonitoringJobsCount}</span></div>
<QueuePopUp connectedToBackend={connectedToBackend} apiUri={apiUri}>
<div className="statusBadge hoverHand"><Icon path={mdiTrayFull} size={1}/> <span>{StandbyJobsCount}</span></div>
<div className="statusBadge hoverHand"><Icon path={mdiRun} size={1}/> <span>{RunningJobsCount}</span></div>
</QueuePopUp>
<div className="statusBadge"><Icon path={mdiCounter} size={1}/> <span>{AllJobsCount}</span></div>
<p id="madeWith">Made with Blåhaj 🦈</p>
</footer>)
2024-10-18 02:10:58 +02:00
}