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 [lastMangaListUpdate, setLastMangaListUpdate] = React.useState<Date>(new Date());
const [lastJobListUpdate, setLastJobListUpdate] = React.useState<Date>(new Date());
const [joblistUpdateInterval, setJoblistUpdateInterval] = React.useState<number>();
useEffect(() => {
checkConnection();
setInterval(() => {
checkConnection();
}, 500);
}, []);
const checkConnection = () =>{
getData('http://127.0.0.1:6531/v2/Ping').then((result) => {
console.log(result);
if(result === null){
setConnected(false);
}else{
setConnected(true);
setConnected(result != null);
}).catch(() => setConnected(false));
}
const interval = setInterval(() => {
useEffect(() => {
if(connected){
setLastJobListUpdate(new Date());
}, 5000);
setJoblistUpdateInterval(setInterval(() => {
setLastJobListUpdate(new Date());
}, 5000));
}else{
clearInterval(joblistUpdateInterval);
setJoblistUpdateInterval(undefined);
}
}, [connected]);
return () => clearInterval(interval);
});
}, []);
const JobsChanged : EventHandler<any> = () => {
setLastMangaListUpdate(new Date());