Check backend connection at intervals, not just on startup

This commit is contained in:
glax 2024-10-20 16:06:21 +02:00
parent 4aff0ed5e0
commit 1304bc750a

View File

@ -12,23 +12,34 @@ export default function App(){
const [showQueue, setShowQueue] = React.useState(false); const [showQueue, setShowQueue] = React.useState(false);
const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date()); const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date());
const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date()); const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date());
const [joblistUpdateInterval, setJoblistUpdateInterval] = React.useState<number>();
useEffect(() => { useEffect(() => {
checkConnection();
setInterval(() => {
checkConnection();
}, 500);
}, []);
const checkConnection = () =>{
getData('http://127.0.0.1:6531/v2/Ping').then((result) => { getData('http://127.0.0.1:6531/v2/Ping').then((result) => {
console.log(result); setConnected(result != null);
if(result === null){ }).catch(() => setConnected(false));
setConnected(false);
}else{
setConnected(true);
} }
const interval = setInterval(() => { useEffect(() => {
if(connected){
setLastJobListUpdate(new Date()); setLastJobListUpdate(new Date());
}, 5000); setJoblistUpdateInterval(setInterval(() => {
setLastJobListUpdate(new Date());
}, 5000));
}else{
clearInterval(joblistUpdateInterval);
setJoblistUpdateInterval(undefined);
}
}, [connected]);
return () => clearInterval(interval);
});
}, []);
const JobsChanged : EventHandler<any> = () => { const JobsChanged : EventHandler<any> = () => {
setLastMangaListUpdate(new Date()); setLastMangaListUpdate(new Date());