check for online/offline events if fetching should be enabled
This commit is contained in:
parent
5f3af74c07
commit
944b99d1ad
|
@ -57,7 +57,29 @@ const fetchNewData = () => {
|
|||
});
|
||||
};
|
||||
|
||||
fetchNewData();
|
||||
setInterval(() => {
|
||||
let intervalHandler = null;
|
||||
|
||||
const stopFetching = () => {
|
||||
if (intervalHandler !== null) {
|
||||
clearInterval(intervalHandler);
|
||||
intervalHandler = null;
|
||||
}
|
||||
};
|
||||
const startFetching = () => {
|
||||
fetchNewData();
|
||||
}, Config.refreshTimeout);
|
||||
if (intervalHandler === null) {
|
||||
intervalHandler = setInterval(() => {
|
||||
fetchNewData();
|
||||
}, Config.refreshTimeout);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('offline', () => {
|
||||
stopFetching();
|
||||
});
|
||||
window.addEventListener('online', () => {
|
||||
startFetching();
|
||||
});
|
||||
if (window.navigator.onLine) {
|
||||
startFetching();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue