Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/connection setter #1596

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/App/App.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import {
DISABLE_TOUR,
ENABLE_ALL_TOURS,
SET_UNLOGGED_USER_LOCATION,
UPDATE_SYMBOLS_SETTINGS
UPDATE_SYMBOLS_SETTINGS,
UPDATE_CONNECTIVITY
} from './App.constants';

import { updateIsInFreeCountry } from '../../providers/SubscriptionProvider/SubscriptionProvider.actions';

export function updateConnectivity({ isConnected = false }) {
return {
type: UPDATE_CONNECTIVITY,
payload: isConnected
};
}

export function updateDisplaySettings(payload = {}) {
return {
type: UPDATE_DISPLAY_SETTINGS,
Expand Down
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
16 changes: 0 additions & 16 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { persistStore } from 'redux-persist';
import { UPDATE_CONNECTIVITY } from './components/App/App.constants';
import googleAnalytics from './analytics';
import createReducer from './reducers';

Expand All @@ -26,21 +25,6 @@ export default function configureStore(initialState = {}) {
composeEnhancers(...enhancers)
);

// TODO refactor not here
window.addEventListener('offline', () => {
store.dispatch({
type: UPDATE_CONNECTIVITY,
payload: false
});
});

window.addEventListener('online', () => {
store.dispatch({
type: UPDATE_CONNECTIVITY,
payload: true
});
});

const persistor = persistStore(store);

return { persistor, store };
Expand Down