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,24 +12,35 @@ export default function App(){
const [showQueue, setShowQueue] = React.useState(false);
const [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date());
const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date());
const [joblistUpdateInterval, setJoblistUpdateInterval] = React.useState<number>();
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<any> = () => {
setLastMangaListUpdate(new Date());
setLastJobListUpdate(new Date());