aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-04-15 16:56:10 -0400
committerIvan Chen <ivan@tagg.id>2021-04-15 16:56:10 -0400
commitf8762fd3a0140bff92fe96985e3abdb9c2925dac (patch)
treef7cc54229a20ee0dc07ec1dada2f256bf4bfd981 /src
parente4a3fb8f1d45a83440454c2eefeea7d312cbe0c5 (diff)
moved CategorySelection and CreateCustomCategory to profile folder
Diffstat (limited to 'src')
-rw-r--r--src/screens/profile/CategorySelection.tsx (renamed from src/screens/onboarding/CategorySelection.tsx)106
-rw-r--r--src/screens/profile/CreateCustomCategory.tsx (renamed from src/screens/onboarding/CreateCustomCategory.tsx)8
-rw-r--r--src/screens/profile/index.ts2
3 files changed, 35 insertions, 81 deletions
diff --git a/src/screens/onboarding/CategorySelection.tsx b/src/screens/profile/CategorySelection.tsx
index ab5ff3be..d3958025 100644
--- a/src/screens/onboarding/CategorySelection.tsx
+++ b/src/screens/profile/CategorySelection.tsx
@@ -1,6 +1,6 @@
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
-import React, {useContext, useEffect, useState} from 'react';
+import React, {useEffect, useState} from 'react';
import {
Alert,
Platform,
@@ -12,28 +12,23 @@ import {
} from 'react-native';
import {ScrollView} from 'react-native-gesture-handler';
import {useDispatch, useSelector} from 'react-redux';
-import {ChatContext} from '../../App';
import PlusIcon from '../../assets/icons/plus_icon-01.svg';
import {Background, MomentCategory} from '../../components';
import {MOMENT_CATEGORIES} from '../../constants';
import {ERROR_SOMETHING_WENT_WRONG} from '../../constants/strings';
-import {OnboardingStackParams} from '../../routes';
-import {postMomentCategories} from '../../services';
-import {
- updateIsOnboardedUser,
- updateMomentCategories,
-} from '../../store/actions/';
+import {MainStackParams} from '../../routes';
+import {updateMomentCategories} from '../../store/actions';
import {RootState} from '../../store/rootReducer';
-import {BackgroundGradientType, CategorySelectionScreenType} from '../../types';
-import {getTokenOrLogout, SCREEN_WIDTH, userLogin} from '../../utils';
+import {BackgroundGradientType} from '../../types';
+import {SCREEN_WIDTH} from '../../utils';
type CategorySelectionRouteProps = RouteProp<
- OnboardingStackParams,
+ MainStackParams,
'CategorySelection'
>;
type CategorySelectionNavigationProps = StackNavigationProp<
- OnboardingStackParams,
+ MainStackParams,
'CategorySelection'
>;
@@ -42,20 +37,11 @@ interface CategorySelectionProps {
navigation: CategorySelectionNavigationProps;
}
-const CategorySelection: React.FC<CategorySelectionProps> = ({
+const CategorySelection: React.FC<CategorySelectioProps> = ({
route,
navigation,
}) => {
- /**
- * Same component to be used for category selection while onboarding and while on profile
- */
- const {screenType, user} = route.params;
- const {chatClient} = useContext(ChatContext);
- const isOnBoarding: boolean =
- screenType === CategorySelectionScreenType.Onboarding;
- const {userId, username} = user;
-
- // During onboarding this will fail and default to []
+ const {newCustomCategory} = route.params;
const {momentCategories = []} = useSelector(
(state: RootState) => state.momentCategories,
);
@@ -81,7 +67,6 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
const dispatch = useDispatch();
useEffect(() => {
- const newCustomCategory = route.params.newCustomCategory;
if (newCustomCategory) {
setUncommitedCustomCategories([
...uncommitedCustomCategories,
@@ -89,23 +74,7 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
]);
selectedCategories.push(newCustomCategory);
}
- }, [route.params?.newCustomCategory]);
-
- /**
- * Show the tutorial if a new user is OnBoarding
- */
- useEffect(() => {
- if (isOnBoarding) {
- navigation.navigate('TaggPopup', {
- popupProps: {
- messageHeader: 'Category And Moments',
- messageBody:
- 'Use pictures and videos to share \ndifferent aspects of you',
- next: undefined,
- },
- });
- }
- }, [isOnBoarding]);
+ }, [newCustomCategory]);
/**
* Handle selection of a new category
@@ -166,20 +135,13 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
return;
}
try {
- if (isOnBoarding) {
- dispatch(updateIsOnboardedUser(true));
- const token = await getTokenOrLogout(dispatch);
- await postMomentCategories(selectedCategories, token);
- userLogin(dispatch, {userId: userId, username: username});
- } else {
- dispatch(
- updateMomentCategories(
- momentCategories.concat(selectedCategories),
- true,
- ),
- );
- navigation.goBack();
- }
+ dispatch(
+ updateMomentCategories(
+ momentCategories.concat(selectedCategories),
+ true,
+ ),
+ );
+ navigation.goBack();
} catch (error) {
console.log(error);
Alert.alert(ERROR_SOMETHING_WENT_WRONG);
@@ -197,24 +159,18 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
<StatusBar barStyle="light-content" />
<Text style={styles.subtext}>Create Categories</Text>
<View style={styles.container}>
- {!isOnBoarding && (
- <TouchableOpacity
- style={styles.createCategory}
- onPress={() => {
- navigation.push('CreateCustomCategory', {
- screenType,
- user,
- existingCategories: momentCategories.concat(
- selectedCategories,
- ),
- });
- }}>
- <PlusIcon width={30} height={30} color="white" />
- <Text style={styles.createCategoryLabel}>
- Create your own category
- </Text>
- </TouchableOpacity>
- )}
+ <TouchableOpacity
+ style={styles.createCategory}
+ onPress={() => {
+ navigation.push('CreateCustomCategory', {
+ existingCategories: momentCategories.concat(selectedCategories),
+ });
+ }}>
+ <PlusIcon width={30} height={30} color="white" />
+ <Text style={styles.createCategoryLabel}>
+ Create your own category
+ </Text>
+ </TouchableOpacity>
<View style={styles.linkerContainer}>
{/* commited custom categories */}
{customCategories.map((category, index) => (
@@ -251,9 +207,7 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
<TouchableOpacity
onPress={handleButtonPress}
style={styles.finalAction}>
- <Text style={styles.finalActionLabel}>
- {isOnBoarding ? 'Login' : 'Create'}
- </Text>
+ <Text style={styles.finalActionLabel}>Create</Text>
</TouchableOpacity>
</View>
</Background>
diff --git a/src/screens/onboarding/CreateCustomCategory.tsx b/src/screens/profile/CreateCustomCategory.tsx
index eab72c7d..c4b17b1e 100644
--- a/src/screens/onboarding/CreateCustomCategory.tsx
+++ b/src/screens/profile/CreateCustomCategory.tsx
@@ -11,17 +11,17 @@ import {
TouchableOpacity,
} from 'react-native';
import {Background} from '../../components';
-import {OnboardingStackParams} from '../../routes';
+import {MainStackParams} from '../../routes';
import {BackgroundGradientType} from '../../types';
import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
type CreateCustomCategoryRouteProps = RouteProp<
- OnboardingStackParams,
+ MainStackParams,
'CreateCustomCategory'
>;
type CreateCustomCategoryNavigationProps = StackNavigationProp<
- OnboardingStackParams,
+ MainStackParams,
'CreateCustomCategory'
>;
@@ -45,8 +45,6 @@ const CreateCustomCategory: React.FC<CreateCustomCategoryProps> = ({
Alert.alert('Looks like you already have that one created!');
} else {
navigation.navigate('CategorySelection', {
- screenType: route.params.screenType,
- user: route.params.user,
newCustomCategory: newCategory,
});
}
diff --git a/src/screens/profile/index.ts b/src/screens/profile/index.ts
index b7efdd3b..d5377494 100644
--- a/src/screens/profile/index.ts
+++ b/src/screens/profile/index.ts
@@ -10,3 +10,5 @@ export {default as InviteFriendsScreen} from './InviteFriendsScreen';
export {default as SettingsScreen} from './SettingsScreen';
export {default as PrivacyScreen} from './PrivacyScreen';
export {default as AccountType} from './AccountType';
+export {default as CategorySelection} from './CategorySelection';
+export {default as CreateCustomCategory} from './CreateCustomCategory';