From 2c69c7a49fcbc92fa1024a0e83c3bad669672e91 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 5 Feb 2021 15:27:00 -0500 Subject: moved permission to routes --- src/App.tsx | 12 +++--------- src/routes/Routes.tsx | 13 +++++++++++++ src/screens/onboarding/CategorySelection.tsx | 3 +-- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') 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 ? : ; }; 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 = ({ const token = await getTokenOrLogout(dispatch); await postMomentCategories(selectedCategories, token); userLogin(dispatch, {userId: userId, username: username}); - fcmService.sendFcmTokenToServer(); } else { dispatch( updateMomentCategories( -- cgit v1.2.3-70-g09d2