diff --git a/Website/App.tsx b/Website/App.tsx index 9ce08a0..40da40f 100644 --- a/Website/App.tsx +++ b/Website/App.tsx @@ -12,24 +12,35 @@ export default function App(){ const [showQueue, setShowQueue] = React.useState(false); const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState(new Date()); const [lastJobListUpdate, setLastJobListUpdate] = React.useState(new Date()); + const [joblistUpdateInterval, setJoblistUpdateInterval] = React.useState(); useEffect(() => { - getData('http://127.0.0.1:6531/v2/Ping').then((result) => { - console.log(result); - if(result === null){ - setConnected(false); - }else{ - setConnected(true); - } - - const interval = setInterval(() => { - setLastJobListUpdate(new Date()); - }, 5000); - - return () => clearInterval(interval); - }); + checkConnection(); + setInterval(() => { + checkConnection(); + }, 500); }, []); + const checkConnection = () =>{ + getData('http://127.0.0.1:6531/v2/Ping').then((result) => { + setConnected(result != null); + }).catch(() => setConnected(false)); + } + + useEffect(() => { + if(connected){ + setLastJobListUpdate(new Date()); + setJoblistUpdateInterval(setInterval(() => { + setLastJobListUpdate(new Date()); + }, 5000)); + }else{ + clearInterval(joblistUpdateInterval); + setJoblistUpdateInterval(undefined); + } + }, [connected]); + + + const JobsChanged : EventHandler = () => { setLastMangaListUpdate(new Date()); setLastJobListUpdate(new Date());