From 41b8a6c3ab2e13f8bba10136628419d2a77ef64f Mon Sep 17 00:00:00 2001 From: AlixH Date: Tue, 14 Dec 2021 15:09:54 +0100 Subject: [PATCH 1/3] Navigation from notifications --- src/notification/NotificationManager.tsx | 55 ++++++++++++------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/notification/NotificationManager.tsx b/src/notification/NotificationManager.tsx index 8448e1550..d5d58c75c 100644 --- a/src/notification/NotificationManager.tsx +++ b/src/notification/NotificationManager.tsx @@ -202,45 +202,36 @@ 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.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + params: { + params: { + chargingStationID: notification.data.chargeBoxID, + connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) + } + } + });*/ this.navigator.dispatch( StackActions.replace('AppDrawerNavigator', { screen: 'ChargingStationsNavigator', @@ -261,6 +252,14 @@ export default class NotificationManager { // Charger just connected case UserNotificationType.SESSION_NOT_STARTED_AFTER_AUTHORIZE: case UserNotificationType.CHARGING_STATION_REGISTERED: + /* this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + params: { + params: { + chargingStationID: notification.data.chargeBoxID, + connectorID: 1 + } + } + });*/ this.navigator.dispatch( StackActions.replace('AppDrawerNavigator', { screen: 'ChargingStationsNavigator', @@ -280,6 +279,8 @@ export default class NotificationManager { break; // Go to Charger list case UserNotificationType.OFFLINE_CHARGING_STATION: + /* this.navigator.navigate('ChargingStationsNavigator', {key: `${Utils.randomNumber()}`, + });*/ this.navigator.dispatch( StackActions.replace('AppDrawerNavigator', { screen: 'ChargingStationsNavigator', From 6fff19b36ac3a48789a4ec0ff856ae0851a4212e Mon Sep 17 00:00:00 2001 From: AlixH Date: Tue, 21 Dec 2021 11:56:14 +0100 Subject: [PATCH 2/3] Fixed notifications navigation when app is closed --- src/App.tsx | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) 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}> + + + + + + ); + } } From d68a0adb3c93369302c5f7477f70bd626beca8ef Mon Sep 17 00:00:00 2001 From: AlixH Date: Tue, 21 Dec 2021 15:57:05 +0100 Subject: [PATCH 3/3] Aligned notifications navigation --- src/notification/NotificationManager.tsx | 52 ++++-------------------- 1 file changed, 7 insertions(+), 45 deletions(-) diff --git a/src/notification/NotificationManager.tsx b/src/notification/NotificationManager.tsx index d5d58c75c..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; } } @@ -224,70 +225,31 @@ export default class NotificationManager { break; case UserNotificationType.CHARGING_STATION_STATUS_ERROR: case UserNotificationType.PREPARING_SESSION_NOT_STARTED: -/* this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, params: { params: { chargingStationID: notification.data.chargeBoxID, connectorID: Utils.getConnectorIDFromConnectorLetter(notification.data.connectorId) } } - });*/ - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'ChargingStationsNavigator', - initial: false, - params: { - screen: 'ChargingStationConnectorDetailsTabs', - key: `${Utils.randomNumber()}`, - params: { - params: { - 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.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, + this.navigator.navigate('ChargingStationsNavigator', {screen: "ChargingStationConnectorDetailsTabs", key: `${Utils.randomNumber()}`, params: { params: { chargingStationID: notification.data.chargeBoxID, connectorID: 1 } } - });*/ - this.navigator.dispatch( - StackActions.replace('AppDrawerNavigator', { - screen: 'ChargingStationsNavigator', - initial: false, - params: { - screen: 'ChargingStationConnectorDetailsTabs', - key: `${Utils.randomNumber()}`, - params: { - params: { - chargingStationID: notification.data.chargeBoxID, - connectorID: 1 - } - } - } - }) - ); + }); break; // Go to Charger list case UserNotificationType.OFFLINE_CHARGING_STATION: - /* this.navigator.navigate('ChargingStationsNavigator', {key: `${Utils.randomNumber()}`, - });*/ - 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: