Auto-update footer counts

This commit is contained in:
glax 2024-10-19 20:15:53 +02:00
parent 09be1c64a3
commit d67b1754f9

View File

@ -9,6 +9,7 @@ export default function App(){
const [connected, setConnected] = React.useState(false); const [connected, setConnected] = React.useState(false);
const [showSearch, setShowSearch] = React.useState(false); const [showSearch, setShowSearch] = 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());
useEffect(() => { useEffect(() => {
getData('http://127.0.0.1:6531/v2/Ping').then((result) => { getData('http://127.0.0.1:6531/v2/Ping').then((result) => {
@ -18,12 +19,19 @@ export default function App(){
}else{ }else{
setConnected(true); setConnected(true);
} }
})
const interval = setInterval(() => {
setLastJobListUpdate(new Date());
}, 1000);
return () => clearInterval(interval);
});
}, []); }, []);
const JobsChanged : EventHandler<any> = () => { const JobsChanged : EventHandler<any> = () => {
console.log("Updating Mangalist"); console.log("Updating Mangalist");
setLastMangaListUpdate(new Date()); setLastMangaListUpdate(new Date());
setLastJobListUpdate(new Date());
} }
return(<div> return(<div>
@ -36,11 +44,10 @@ export default function App(){
<hr/> <hr/>
</> </>
: <></>} : <></>}
<MonitorJobsList onStartSearch={() => setShowSearch(true)} onJobsChanged={JobsChanged} <MonitorJobsList onStartSearch={() => setShowSearch(true)} onJobsChanged={JobsChanged} key={lastMangaListUpdate.getTime()}/>
key={lastMangaListUpdate.getTime()}/>
</> </>
: <h1>No connection to backend</h1>} : <h1>No connection to backend</h1>}
<Footer/> <Footer key={lastJobListUpdate.getTime()} />
</div>) </div>)
} }