Skip to content

Commit

Permalink
Merge pull request sap-labs-france#588 from sap-labs-france/hotfix
Browse files Browse the repository at this point in the history
Fixed notifications navigation
  • Loading branch information
LucasBrazi06 authored Jan 3, 2022
2 parents 6b82ba1 + d68a0ad commit 95cc56b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 88 deletions.
49 changes: 23 additions & 26 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,25 +477,6 @@ function createAppDrawerNavigator(props: BaseProps) {
);
}

function createRootNavigator(app: App, initialState: InitialState) {
return (
<NavigationContainer
ref={(navigatorRef) => {
if (navigatorRef) {
app.notificationManager?.initialize(navigatorRef);
app.deepLinkingManager?.initialize(navigatorRef, app.centralServerProvider);
}
}}
onStateChange={persistNavigationState}
initialState={initialState}>
<rootStack.Navigator initialRouteName="AuthNavigator" screenOptions={{ headerShown: false }}>
<rootStack.Screen name="AuthNavigator" component={createAuthNavigator} />
<rootStack.Screen name="AppDrawerNavigator" component={createAppDrawerNavigator} />
</rootStack.Navigator>
</NavigationContainer>
);
}

export interface Props {}
interface State {
switchTheme?: boolean;
Expand Down Expand Up @@ -548,21 +529,17 @@ export default class App extends React.Component<Props, State> {
// 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
});
}

Expand All @@ -584,9 +561,29 @@ export default class App extends React.Component<Props, State> {
<AppUpdateDialog appVersion={this.appVersion} close={() => this.setState({ showAppUpdateDialog: false })} />
)}
<StatusBar barStyle={ThemeManager.getInstance()?.isThemeTypeIsDark() ? 'light-content' : 'dark-content'} translucent backgroundColor="transparent" />
{createRootNavigator(this, this.state.navigationState)}
{this.createRootNavigator()}
</RootSiblingParent>
)
);
}

private createRootNavigator() {
return (
<NavigationContainer
ref={(navigatorRef) => {
if (navigatorRef) {
this.notificationManager?.initialize(navigatorRef);
this.notificationManager.checkOnHoldNotification();
this.deepLinkingManager?.initialize(navigatorRef, this.centralServerProvider);
}
}}
onStateChange={persistNavigationState}
initialState={this.state.navigationState}>
<rootStack.Navigator initialRouteName="AuthNavigator" screenOptions={{ headerShown: false }}>
<rootStack.Screen name="AuthNavigator" component={createAuthNavigator} />
<rootStack.Screen name="AppDrawerNavigator" component={createAppDrawerNavigator} />
</rootStack.Navigator>
</NavigationContainer>
);
}
}
87 changes: 25 additions & 62 deletions src/notification/NotificationManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class NotificationManager {
if (enabled) {
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
console.log(fcmToken);
this.token = fcmToken;
}
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 95cc56b

Please sign in to comment.