feat: auto-refresh the scan button until the worker finishes
This commit is contained in:
@@ -39,6 +39,16 @@ export function SettingsForm() {
|
|||||||
setScanRequested(true);
|
setScanRequested(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!scanRequested) return;
|
||||||
|
const id = setInterval(async () => {
|
||||||
|
const s = await (await fetch("/api/scan")).json();
|
||||||
|
setScanResult(s.result);
|
||||||
|
if (!s.requested) setScanRequested(false); // worker finished the scan
|
||||||
|
}, 2000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, [scanRequested]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("/api/config")
|
fetch("/api/config")
|
||||||
.then((r) => r.json())
|
.then((r) => r.json())
|
||||||
|
|||||||
Reference in New Issue
Block a user