import React, {useEffect} from 'react'; import '../styles/footer.css'; import Job from './Job'; import Icon from '@mdi/react'; import { mdiRun, mdiCounter, mdiEyeCheck, mdiTrayFull } from '@mdi/js'; import QueuePopUp from "./QueuePopUp"; export default function Footer({connectedToBackend, apiUri} : {connectedToBackend: boolean, apiUri: string}) { 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(); function UpdateBackendState(){ 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)); } useEffect(() => { if(connectedToBackend){ UpdateBackendState(); setCountUpdateInterval(setInterval(() => { UpdateBackendState(); }, 2000)); }else{ clearInterval(countUpdateInterval); setCountUpdateInterval(undefined); } }, [connectedToBackend]); return ( ) }