Skip to content

Commit

Permalink
Configure connection status during mount of the app container
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivm committed Oct 19, 2023
1 parent 44288bb commit c47e941
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/components/App/App.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -148,7 +179,8 @@ const mapDispatchToProps = {
showNotification,
updateUserDataFromAPI,
updateLoggedUserLocation,
updateUnloggedUserLocation
updateUnloggedUserLocation,
updateConnectivity
};

export default connect(
Expand Down

0 comments on commit c47e941

Please sign in to comment.