aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx12
-rw-r--r--src/routes/Routes.tsx13
-rw-r--r--src/screens/onboarding/CategorySelection.tsx3
3 files changed, 17 insertions, 11 deletions
diff --git a/src/App.tsx b/src/App.tsx
index 18fadf64..ea3617dc 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,17 +1,11 @@
-import React, {useEffect} from 'react';
import {NavigationContainer} from '@react-navigation/native';
-import Routes from './routes';
+import React from 'react';
import {Provider} from 'react-redux';
-import store from './store/configureStore';
-import {fcmService} from './services/FCMService';
import {navigationRef} from './RootNavigation';
+import Routes from './routes';
+import store from './store/configureStore';
const App = () => {
- useEffect(() => {
- fcmService.setUpPushNotifications();
- // TODO: If permissions are not there, deactivateFcmService
- });
-
return (
/**
* This is the provider from the redux store, it acts as the root provider for our application
diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx
index a14f1576..768a7604 100644
--- a/src/routes/Routes.tsx
+++ b/src/routes/Routes.tsx
@@ -7,12 +7,14 @@ import {userLogin} from '../utils';
import SplashScreen from 'react-native-splash-screen';
import messaging from '@react-native-firebase/messaging';
import {updateNewNotificationReceived} from '../store/actions';
+import {fcmService} from '../services';
const Routes: React.FC = () => {
const {
user: {userId},
} = useSelector((state: RootState) => state.user);
const dispatch = useDispatch();
+ const {isOnboardedUser} = useSelector((state: RootState) => state.user);
/**
* Load the user from AsyncStorage if any
@@ -39,6 +41,17 @@ const Routes: React.FC = () => {
}
}, [dispatch, userId]);
+ useEffect(() => {
+ // after onboarding, or user signed in (after reinstall)
+ if (userId) {
+ fcmService.setUpPushNotifications();
+ }
+ // user just onboarded
+ if (isOnboardedUser) {
+ fcmService.sendFcmTokenToServer();
+ }
+ });
+
return userId ? <NavigationBar /> : <Onboarding />;
};
diff --git a/src/screens/onboarding/CategorySelection.tsx b/src/screens/onboarding/CategorySelection.tsx
index a3acbbb7..94dd44b2 100644
--- a/src/screens/onboarding/CategorySelection.tsx
+++ b/src/screens/onboarding/CategorySelection.tsx
@@ -17,7 +17,7 @@ import {Background, MomentCategory} from '../../components';
import {MOMENT_CATEGORIES} from '../../constants';
import {ERROR_SOMETHING_WENT_WRONG} from '../../constants/strings';
import {OnboardingStackParams} from '../../routes';
-import {fcmService, postMomentCategories} from '../../services';
+import {postMomentCategories} from '../../services';
import {
updateIsOnboardedUser,
updateMomentCategories,
@@ -169,7 +169,6 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
const token = await getTokenOrLogout(dispatch);
await postMomentCategories(selectedCategories, token);
userLogin(dispatch, {userId: userId, username: username});
- fcmService.sendFcmTokenToServer();
} else {
dispatch(
updateMomentCategories(