diff --git a/src/components/App/App.container.js b/src/components/App/App.container.js index f481cc10d..14103fc84 100644 --- a/src/components/App/App.container.js +++ b/src/components/App/App.container.js @@ -13,7 +13,8 @@ import { DISPLAY_SIZE_STANDARD } from '../Settings/Display/Display.constants'; import { updateUserDataFromAPI, updateLoggedUserLocation, - updateUnloggedUserLocation + updateUnloggedUserLocation, + updateConnectivity } from '../App/App.actions'; import { isCordova, isElectron } from '../../cordova-util'; export class AppContainer extends Component { @@ -85,6 +86,36 @@ export class AppContainer extends Component { localizeUser(); if (isCordova()) initCVAGa4(); + + const configureConnectionStatus = () => { + const { updateConnectivity } = this.props; + const setAsOnline = () => { + updateConnectivity({ isConnected: true }); + }; + + const setAsOffline = () => { + updateConnectivity({ isConnected: false }); + }; + + const addConnectionEventListeners = () => { + window.addEventListener('offline', setAsOffline); + window.addEventListener('online', setAsOnline); + }; + + const setCurrentConnectionStatus = () => { + if (!navigator.onLine) { + setAsOffline(); + return; + } + setAsOnline(); + return; + }; + + setCurrentConnectionStatus(); + addConnectionEventListeners(); + }; + + configureConnectionStatus(); } handleNewContentAvailable = () => { @@ -148,7 +179,8 @@ const mapDispatchToProps = { showNotification, updateUserDataFromAPI, updateLoggedUserLocation, - updateUnloggedUserLocation + updateUnloggedUserLocation, + updateConnectivity }; export default connect(