From a954d6b6b88485dddc0ccfda634ffd102cb34ccd Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Tue, 22 Dec 2020 08:50:27 -0800 Subject: [TMA 446] Create category (#144) * Added welcome page * Working code * Small fix * Some more cleanup * Fixes * Cleanup * Fix again * Use gradient for white bg as well * Fixed type --- src/components/profile/Content.tsx | 96 ++++++++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 8 deletions(-) (limited to 'src/components/profile') diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index f2e0db0a..7064f775 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -1,21 +1,29 @@ import React, {useCallback, useEffect, useState} from 'react'; import { + Alert, LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, RefreshControl, StyleSheet, + Text, View, } from 'react-native'; import Animated from 'react-native-reanimated'; import { + CategorySelectionScreenType, + MomentCategoryType, MomentType, ProfilePreviewType, ProfileType, ScreenType, UserType, } from '../../types'; -import {COVER_HEIGHT, defaultMoments} from '../../constants'; +import { + COVER_HEIGHT, + MOMENT_CATEGORIES, + TAGG_TEXT_LIGHT_BLUE, +} from '../../constants'; import {fetchUserX, SCREEN_HEIGHT, userLogin} from '../../utils'; import TaggsBar from '../taggs/TaggsBar'; import {Moment} from '../moments'; @@ -29,15 +37,19 @@ import { blockUnblockUser, loadFollowData, updateUserXFollowersAndFollowing, + updateMomentCategories, } from '../../store/actions'; import { NO_USER, NO_PROFILE, EMPTY_PROFILE_PREVIEW_LIST, EMPTY_MOMENTS_LIST, + MOMENT_CATEGORIES_MAP, } from '../../store/initialStates'; import {Cover} from '.'; -import {Background} from '../onboarding'; +import {TouchableOpacity} from 'react-native-gesture-handler'; +import {useNavigation} from '@react-navigation/native'; +import {deleteMomentCategories} from '../../services'; interface ContentProps { y: Animated.Value; @@ -60,6 +72,10 @@ const Content: React.FC = ({y, userXId, screenType}) => { ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.moments); + const {momentCategories = MOMENT_CATEGORIES_MAP} = userXId + ? useSelector((state: RootState) => state.userX[screenType][userXId]) + : useSelector((state: RootState) => state.momentCategories); + const {blockedUsers = EMPTY_PROFILE_PREVIEW_LIST} = useSelector( (state: RootState) => state.blocked, ); @@ -68,6 +84,8 @@ const Content: React.FC = ({y, userXId, screenType}) => { ); const state = useStore().getState(); + const navigation = useNavigation(); + /** * States */ @@ -80,6 +98,13 @@ const Content: React.FC = ({y, userXId, screenType}) => { const [shouldBounce, setShouldBounce] = useState(true); const [refreshing, setRefreshing] = useState(false); + /** + * Filter list of categories already selected by user + */ + const userMomentCategories = MOMENT_CATEGORIES.filter( + (category) => momentCategories[category] === true, + ); + const onRefresh = useCallback(() => { const refrestState = async () => { if (!userXId) { @@ -194,6 +219,33 @@ const Content: React.FC = ({y, userXId, screenType}) => { await dispatch(updateUserXFollowersAndFollowing(user.userId, state)); }; + /** + * Handle deletion of a category + * Confirm with user before deleting the category + * @param category category to be deleted + */ + const handleCategoryDeletion = (category: MomentCategoryType) => { + Alert.alert( + 'Category Deletion', + `Are you sure that you want to delete the category ${category} ?`, + [ + { + text: 'Cancel', + style: 'cancel', + }, + { + text: 'Yes', + onPress: () => { + dispatch( + updateMomentCategories([category], false, loggedInUser.userId), + ); + }, + }, + ], + {cancelable: true}, + ); + }; + const handleScroll = (e: NativeSyntheticEvent) => { /** * Set the new y position @@ -239,32 +291,60 @@ const Content: React.FC = ({y, userXId, screenType}) => { /> - {defaultMoments.map((title, index) => ( + {userMomentCategories.map((title, index) => ( 2} /> ))} + {!userXId && userMomentCategories.length < 6 && ( + + navigation.push('CategorySelection', { + categories: momentCategories, + screenType: CategorySelectionScreenType.Profile, + user: loggedInUser, + }) + } + style={styles.createCategoryButton}> + + Create a new category + + + )} ); }; const styles = StyleSheet.create({ - refreshControlContainer: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - }, container: { flex: 1, }, momentsContainer: { backgroundColor: '#f2f2f2', paddingBottom: SCREEN_HEIGHT / 10, + flex: 1, + flexDirection: 'column', + }, + createCategoryButton: { + backgroundColor: TAGG_TEXT_LIGHT_BLUE, + justifyContent: 'center', + alignItems: 'center', + width: '70%', + height: 30, + marginTop: '15%', + alignSelf: 'center', + }, + createCategoryButtonLabel: { + fontSize: 16, + fontWeight: '500', + color: 'white', }, }); -- cgit v1.2.3-70-g09d2