feat(donate): auto reload widget when too many failures
This commit is contained in:
@@ -20,6 +20,7 @@ type DonateData = {
|
|||||||
export default function () {
|
export default function () {
|
||||||
const [current, setCurrent] = useState<DonateData>();
|
const [current, setCurrent] = useState<DonateData>();
|
||||||
const [mounted, setMounted] = useState(false);
|
const [mounted, setMounted] = useState(false);
|
||||||
|
const [failed, setFailed] = useState(0);
|
||||||
const sfx = useRef<HTMLAudioElement | null>(null);
|
const sfx = useRef<HTMLAudioElement | null>(null);
|
||||||
const onQueue = useRef<string[]>([]);
|
const onQueue = useRef<string[]>([]);
|
||||||
const queue = useRef<Promise<void>>(Promise.resolve());
|
const queue = useRef<Promise<void>>(Promise.resolve());
|
||||||
@@ -87,8 +88,11 @@ export default function () {
|
|||||||
try {
|
try {
|
||||||
await promise;
|
await promise;
|
||||||
console.log("Heartbeat OK");
|
console.log("Heartbeat OK");
|
||||||
|
setFailed(0);
|
||||||
} catch {
|
} catch {
|
||||||
console.error("Heartbeat timed out");
|
console.error("Heartbeat timed out");
|
||||||
|
setFailed((x) => x + 1);
|
||||||
|
if (failed > 12) location.reload();
|
||||||
}
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user