Move all status/alert dialogs into the Left Pane
This commit is contained in:
parent
101070bf42
commit
18fd44f504
50 changed files with 1298 additions and 607 deletions
40
ts/services/networkObserver.ts
Normal file
40
ts/services/networkObserver.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import {
|
||||
CheckNetworkStatusPayloadType,
|
||||
NetworkActionType,
|
||||
} from '../state/ducks/network';
|
||||
import { getSocketStatus } from '../shims/socketStatus';
|
||||
|
||||
type NetworkActions = {
|
||||
checkNetworkStatus: (x: CheckNetworkStatusPayloadType) => NetworkActionType;
|
||||
closeConnectingGracePeriod: () => NetworkActionType;
|
||||
};
|
||||
|
||||
const REFRESH_INTERVAL = 5000;
|
||||
|
||||
interface ShimmedWindow extends Window {
|
||||
log: {
|
||||
info: (...args: any) => void;
|
||||
};
|
||||
}
|
||||
|
||||
const unknownWindow = window as unknown;
|
||||
const shimmedWindow = unknownWindow as ShimmedWindow;
|
||||
|
||||
export function initializeNetworkObserver(networkActions: NetworkActions) {
|
||||
const { log } = shimmedWindow;
|
||||
log.info(`Initializing network observer every ${REFRESH_INTERVAL}ms`);
|
||||
|
||||
const refresh = () => {
|
||||
networkActions.checkNetworkStatus({
|
||||
isOnline: navigator.onLine,
|
||||
socketStatus: getSocketStatus(),
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('online', refresh);
|
||||
window.addEventListener('offline', refresh);
|
||||
window.setInterval(refresh, REFRESH_INTERVAL);
|
||||
window.setTimeout(() => {
|
||||
networkActions.closeConnectingGracePeriod();
|
||||
}, REFRESH_INTERVAL);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue