diff --git a/src/App.tsx b/src/App.tsx index c485ddd6a..2b8d16a61 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -477,25 +477,6 @@ function createAppDrawerNavigator(props: BaseProps) { ); } -function createRootNavigator(app: App, initialState: InitialState) { - return ( - { - if (navigatorRef) { - app.notificationManager?.initialize(navigatorRef); - app.deepLinkingManager?.initialize(navigatorRef, app.centralServerProvider); - } - }} - onStateChange={persistNavigationState} - initialState={initialState}> - - - - - - ); -} - export interface Props {} interface State { switchTheme?: boolean; @@ -548,21 +529,17 @@ export default class App extends React.Component { // Location ------------------------------------------------ this.location = await LocationManager.getInstance(); this.location.startListening(); - // Check on hold notification - this.notificationManager.checkOnHoldNotification(); // Check migration const migrationManager = MigrationManager.getInstance(); migrationManager.setCentralServerProvider(this.centralServerProvider); await migrationManager.migrate(); // Check for app updates this.appVersion = await checkVersion(); - if (this.appVersion?.needsUpdate) { - this.setState({ showAppUpdateDialog: true }); - } // Set this.setState({ navigationState, - isNavigationStateLoaded: true + isNavigationStateLoaded: true, + showAppUpdateDialog: !!this.appVersion?.needsUpdate }); } @@ -584,9 +561,29 @@ export default class App extends React.Component { this.setState({ showAppUpdateDialog: false })} /> )} - {createRootNavigator(this, this.state.navigationState)} + {this.createRootNavigator()} ) ); } + + private createRootNavigator() { + return ( + { + if (navigatorRef) { + this.notificationManager?.initialize(navigatorRef); + this.notificationManager.checkOnHoldNotification(); + this.deepLinkingManager?.initialize(navigatorRef, this.centralServerProvider); + } + }} + onStateChange={persistNavigationState} + initialState={this.state.navigationState}> + + + + + + ); + } } diff --git a/src/notification/NotificationManager.tsx b/src/notification/NotificationManager.tsx index 8448e1550..fca76af40 100644 --- a/src/notification/NotificationManager.tsx +++ b/src/notification/NotificationManager.tsx @@ -55,6 +55,7 @@ export default class NotificationManager { if (enabled) { const fcmToken = await firebase.messaging().getToken(); if (fcmToken) { + console.log(fcmToken); this.token = fcmToken; } } @@ -202,91 +203,53 @@ export default class NotificationManager { switch (notification.data.notificationType) { // End of Transaction case UserNotificationType.END_OF_SESSION: - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'TransactionHistoryNavigator', - initial: false, - params: { - screen: 'TransactionDetailsTabs', - key: `${Utils.randomNumber()}`, + this.navigator.navigate('TransactionHistoryNavigator', {screen: "TransactionDetailsTabs", key: `${Utils.randomNumber()}`, + params: { params: { - params: { - transactionID: Utils.convertToInt(notification.data.transactionId) - } + transactionID: Utils.convertToInt(notification.data.transactionId) } - } - }) - ); + }}); break; // Session In Progress case UserNotificationType.SESSION_STARTED: case UserNotificationType.END_OF_CHARGE: case UserNotificationType.OPTIMAL_CHARGE_REACHED: - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'TransactionInProgressNavigator', - initial: false, + this.navigator.navigate('TransactionInProgressNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + params: { params: { - screen: 'ChargingStationConnectorDetailsTabs', - key: `${Utils.randomNumber()}`, - params: { - params: { - chargingStationID: notification.data.chargeBoxID, - connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) - } - } + chargingStationID: notification.data.chargeBoxID, + connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) } - }) - ); + } + }); break; case UserNotificationType.CHARGING_STATION_STATUS_ERROR: case UserNotificationType.PREPARING_SESSION_NOT_STARTED: - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'ChargingStationsNavigator', - initial: false, + this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + params: { params: { - screen: 'ChargingStationConnectorDetailsTabs', - key: `${Utils.randomNumber()}`, - params: { - params: { - chargingStationID: notification.data.chargeBoxID, - connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) - } - } + chargingStationID: notification.data.chargeBoxID, + connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) } - }) - ); + } + }); break; // Charger just connected case UserNotificationType.SESSION_NOT_STARTED_AFTER_AUTHORIZE: case UserNotificationType.CHARGING_STATION_REGISTERED: - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'ChargingStationsNavigator', - initial: false, + this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + params: { params: { - screen: 'ChargingStationConnectorDetailsTabs', - key: `${Utils.randomNumber()}`, - params: { - params: { - chargingStationID: notification.data.chargeBoxID, - connectorID: 1 - } - } + chargingStationID: notification.data.chargeBoxID, + connectorID: 1 } - }) - ); + } + }); break; // Go to Charger list case UserNotificationType.OFFLINE_CHARGING_STATION: - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'ChargingStationsNavigator', - initial: false, - key: `${Utils.randomNumber()}` - }) - ); + this.navigator.navigate('ChargingStationsNavigator', {key: `${Utils.randomNumber()}`, + }); break; // No need to navigate case UserNotificationType.UNKNOWN_USER_BADGED: