From 653aae1cd0409effdd14e215078986737c4c65ef Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 1 Jun 2021 18:32:38 -0400 Subject: Finish profile badges component --- src/components/profile/ProfileBadges.tsx | 98 ++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 16 deletions(-) (limited to 'src/components') diff --git a/src/components/profile/ProfileBadges.tsx b/src/components/profile/ProfileBadges.tsx index 13e775f7..39e84705 100644 --- a/src/components/profile/ProfileBadges.tsx +++ b/src/components/profile/ProfileBadges.tsx @@ -1,12 +1,15 @@ +import {useNavigation} from '@react-navigation/core'; import React, {useEffect, useState} from 'react'; -import {Alert, StyleSheet, Text, View} from 'react-native'; -import {ScrollView} from 'react-native-gesture-handler'; +import {StyleSheet, Text, View} from 'react-native'; +import {ScrollView, TouchableOpacity} from 'react-native-gesture-handler'; import {useSelector} from 'react-redux'; import {BadgeIcon} from '..'; import PlusIcon from '../../assets/icons/plus_icon-01.svg'; +import {BADGE_LIMIT} from '../../constants'; import {RootState} from '../../store/rootReducer'; import {ScreenType, UniversityBadgeDisplayType} from '../../types'; import {badgesToDisplayBadges, normalize} from '../../utils'; +import BadgeDetailView from '../common/BadgeDetailView'; interface ProfileBadgesProps { userXId: string | undefined; @@ -14,12 +17,14 @@ interface ProfileBadgesProps { } const ProfileBadges: React.FC = ({userXId, screenType}) => { - const {badges} = useSelector((state: RootState) => + const navigation = useNavigation(); + const {badges, name} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId].profile : state.user.profile, ); const [displayBadges, setDisplayBadges] = useState< UniversityBadgeDisplayType[] >([]); + const [isEditBadgeModalVisible, setIsEditBadgeModalVisible] = useState(false); useEffect(() => { setDisplayBadges(badgesToDisplayBadges(badges)); @@ -27,6 +32,7 @@ const ProfileBadges: React.FC = ({userXId, screenType}) => { return ( <> + {/* Tutorial text */} {displayBadges.length === 0 && ( <> Badges @@ -36,24 +42,81 @@ const ProfileBadges: React.FC = ({userXId, screenType}) => { )} {displayBadges.length === 0 ? ( - - Alert.alert('fooo')} - /> - {[0, 0, 0, 0, 0].map(() => ( - - ))} + // Grey circle placeholders + + + navigation.navigate('BadgeSelection', {editing: true}) + }> + + + {Array(BADGE_LIMIT) + .fill(0) + .map(() => ( + + ))} ) : ( - + // Populating actual badges + + {/* Actual badges */} {displayBadges.map((displayBadge) => ( ))} + {/* Plus icon */} + {displayBadges.length < BADGE_LIMIT && ( + + navigation.navigate('BadgeSelection', {editing: true}) + }> + + + )} + {/* Empty placeholders for space-between styling */} + {Array(BADGE_LIMIT + 1) + .fill(0) + .splice(displayBadges.length + 1, BADGE_LIMIT) + .map(() => ( + + ))} + {/* X button */} + {displayBadges.length === BADGE_LIMIT && ( + setIsEditBadgeModalVisible(true)}> + + + )} )} + {isEditBadgeModalVisible && ( + + )} ); }; @@ -67,16 +130,19 @@ const styles = StyleSheet.create({ body: { fontSize: normalize(13.5), lineHeight: normalize(17), + marginBottom: 10, }, badgeContainer: { width: '100%', - borderWidth: 1, justifyContent: 'space-between', + marginBottom: 15, }, - greyCircle: { + circle: { width: normalize(31), height: normalize(31), borderRadius: normalize(31) / 2, + }, + grey: { backgroundColor: '#c4c4c4', }, }); -- cgit v1.2.3-70-g09d2