From 4ec594d00b897ac9882a65a60f0523bbe5dbcb0f Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 3 Feb 2021 07:41:39 -0800 Subject: New screen to request permission to contacts --- src/routes/main/MainStackNavigator.tsx | 3 +++ src/routes/main/MainStackScreen.tsx | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/routes') diff --git a/src/routes/main/MainStackNavigator.tsx b/src/routes/main/MainStackNavigator.tsx index bd838ef2..e038d2c2 100644 --- a/src/routes/main/MainStackNavigator.tsx +++ b/src/routes/main/MainStackNavigator.tsx @@ -14,6 +14,9 @@ export type MainStackParams = { Search: { screenType: ScreenType; }; + RequestContactsAccess: { + screenType: ScreenType; + }; Profile: { userXId: string | undefined; screenType: ScreenType; diff --git a/src/routes/main/MainStackScreen.tsx b/src/routes/main/MainStackScreen.tsx index 3e425101..8042d267 100644 --- a/src/routes/main/MainStackScreen.tsx +++ b/src/routes/main/MainStackScreen.tsx @@ -12,6 +12,7 @@ import { MomentUploadPromptScreen, NotificationsScreen, ProfileScreen, + RequestContactsAccess, SearchScreen, SocialMediaTaggs, } from '../../screens'; @@ -47,7 +48,14 @@ const MainStackScreen: React.FC = ({route}) => { case ScreenType.Profile: return 'Profile'; case ScreenType.Search: - return 'Search'; + // Check if user responded to access contacts and return appropriate screen + // When app is opened, load the value from Async Storage to react native store + // Every time the user clicks on this tab + // Retrieve the information from the store + // If responded is true, show search screen + // Else, show RequestContactsAccess + // If user responds, update store and Async and remove popup + return 'RequestContactsAccess'; case ScreenType.Notifications: return 'Notifications'; } @@ -91,9 +99,14 @@ const MainStackScreen: React.FC = ({route}) => { }} /> {isSearchTab && ( + // )} -- cgit v1.2.3-70-g09d2 From bbc7d3b3169e145708c6646a6f4003fc2735f1fb Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 3 Feb 2021 10:51:11 -0800 Subject: Enabled button functionality --- src/routes/main/MainStackScreen.tsx | 39 ++++++++++++++++++---------- src/screens/search/RequestContactsAccess.tsx | 27 ++++++++++++++++--- 2 files changed, 48 insertions(+), 18 deletions(-) (limited to 'src/routes') diff --git a/src/routes/main/MainStackScreen.tsx b/src/routes/main/MainStackScreen.tsx index 8042d267..15695288 100644 --- a/src/routes/main/MainStackScreen.tsx +++ b/src/routes/main/MainStackScreen.tsx @@ -1,6 +1,7 @@ +import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationOptions} from '@react-navigation/stack'; -import React from 'react'; +import React, {useState} from 'react'; import { CaptionScreen, CategorySelection, @@ -43,6 +44,14 @@ const MainStackScreen: React.FC = ({route}) => { const isSearchTab = screenType === ScreenType.Search; const isNotificationsTab = screenType === ScreenType.Notifications; + AsyncStorage.getItem('respondedToAccessContacts').then((value) => + setRespondedToAccessContacts(value ? value : 'false'), + ); + + const [respondedToAccessContacts, setRespondedToAccessContacts] = useState( + 'false', + ); + const initialRouteName = (() => { switch (screenType) { case ScreenType.Profile: @@ -55,7 +64,7 @@ const MainStackScreen: React.FC = ({route}) => { // If responded is true, show search screen // Else, show RequestContactsAccess // If user responds, update store and Async and remove popup - return 'RequestContactsAccess'; + return 'Search'; case ScreenType.Notifications: return 'Notifications'; } @@ -98,18 +107,20 @@ const MainStackScreen: React.FC = ({route}) => { screenType, }} /> - {isSearchTab && ( - // - - )} + {isSearchTab && + (respondedToAccessContacts && respondedToAccessContacts === 'true' ? ( + + ) : ( + + ))} {isNotificationsTab && ( { const navigation = useNavigation(); + + const handleAllowAccess = async () => { + checkPermission().then((permission) => { + if (permission === 'undefined') { + requestPermission().then((response) => { + if (response === 'authorized' || response === 'denied') { + navigation.navigate('Search'); + } + }); + } + }); + await AsyncStorage.setItem('respondedToAccessContacts', 'true'); + }; + + const handleDontAllowAccess = async () => { + await AsyncStorage.setItem('respondedToAccessContacts', 'true'); + navigation.navigate('Search'); + }; + return ( { { - console.log('Show IOS opoup'); - }} + onPress={handleAllowAccess} style={styles.allowButton}> Allow Contacts navigation.pop()}> + onPress={handleDontAllowAccess}> Don’t Allow -- cgit v1.2.3-70-g09d2 From a3019b1be25db59c5c80305c8bc6769254a222cd Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 3 Feb 2021 11:33:56 -0800 Subject: removed unnecessary comment --- src/routes/main/MainStackScreen.tsx | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/routes') diff --git a/src/routes/main/MainStackScreen.tsx b/src/routes/main/MainStackScreen.tsx index 15695288..76fc55e0 100644 --- a/src/routes/main/MainStackScreen.tsx +++ b/src/routes/main/MainStackScreen.tsx @@ -57,13 +57,6 @@ const MainStackScreen: React.FC = ({route}) => { case ScreenType.Profile: return 'Profile'; case ScreenType.Search: - // Check if user responded to access contacts and return appropriate screen - // When app is opened, load the value from Async Storage to react native store - // Every time the user clicks on this tab - // Retrieve the information from the store - // If responded is true, show search screen - // Else, show RequestContactsAccess - // If user responds, update store and Async and remove popup return 'Search'; case ScreenType.Notifications: return 'Notifications'; -- cgit v1.2.3-70-g09d2 From a2423b84581a9f1997bac578115071fd3350d535 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 3 Feb 2021 19:04:15 -0800 Subject: pushing screen in - normal screen --- src/routes/main/MainStackScreen.tsx | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/routes') diff --git a/src/routes/main/MainStackScreen.tsx b/src/routes/main/MainStackScreen.tsx index 3e425101..47b49f07 100644 --- a/src/routes/main/MainStackScreen.tsx +++ b/src/routes/main/MainStackScreen.tsx @@ -180,9 +180,6 @@ const MainStackScreen: React.FC = ({route}) => { 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/routes') 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 From 94d38350ba0bcfd0bc3095d8628de67fbe6ee6dc Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 5 Feb 2021 15:29:15 -0500 Subject: always send token --- src/routes/Routes.tsx | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/routes') diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx index 768a7604..a5383a47 100644 --- a/src/routes/Routes.tsx +++ b/src/routes/Routes.tsx @@ -14,7 +14,6 @@ const Routes: React.FC = () => { user: {userId}, } = useSelector((state: RootState) => state.user); const dispatch = useDispatch(); - const {isOnboardedUser} = useSelector((state: RootState) => state.user); /** * Load the user from AsyncStorage if any @@ -42,12 +41,8 @@ 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(); } }); -- cgit v1.2.3-70-g09d2