From 353c1ec685698bb86e0ff96a346d88205ee389cf Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 13 Jan 2021 02:58:24 -0500 Subject: [TMA-531] New Explore Page (#179) * redux done * done * added refresh control * added profile navigation * minor spacing change --- src/components/profile/ProfilePreview.tsx | 7 +-- src/components/search/Explore.tsx | 35 ++++++------ src/components/search/ExploreSection.tsx | 26 +++++---- src/components/search/ExploreSectionUser.tsx | 81 +++++++++++++++++++++++----- 4 files changed, 105 insertions(+), 44 deletions(-) (limited to 'src/components') diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index bd015811..6f008540 100644 --- a/src/components/profile/ProfilePreview.tsx +++ b/src/components/profile/ProfilePreview.tsx @@ -147,7 +147,8 @@ const ProfilePreview: React.FC = ({ screenType, ); } - const userXId = loggedInUser.username === user.username ? undefined : user.id; + const userXId = + loggedInUser.username === user.username ? undefined : user.id; navigation.push('Profile', { userXId, screenType, @@ -205,7 +206,6 @@ const ProfilePreview: React.FC = ({ usernameStyle = styles.searchResultUsername; nameStyle = styles.searchResultName; } - return ( { - const sections: Array = [ - 'People you follow', - 'People you may know', - 'Trending in sports', - 'Trending on Tagg', - 'Trending in music', - ]; - const users: Array = [ - 'Sam Davis', - 'Becca Smith', - 'Ann Taylor', - 'Clara Johnson', - 'Sarah Jung', - 'Lila Hernandez', - ]; + const {explores} = useSelector((state: RootState) => state.taggUsers); return ( - {sections.map((title) => ( - + Search Profiles + {EXPLORE_SECTION_TITLES.map((title: ExploreSectionType) => ( + ))} ); @@ -30,6 +21,14 @@ const Explore: React.FC = () => { const styles = StyleSheet.create({ container: { zIndex: 0, + // margin: '5%', + }, + header: { + fontWeight: '700', + fontSize: 22, + color: '#fff', + marginBottom: '2%', + margin: '5%', }, }); export default Explore; diff --git a/src/components/search/ExploreSection.tsx b/src/components/search/ExploreSection.tsx index 8e826bd9..8e8b4988 100644 --- a/src/components/search/ExploreSection.tsx +++ b/src/components/search/ExploreSection.tsx @@ -1,5 +1,6 @@ -import React from 'react'; -import {View, Text, ScrollView, StyleSheet} from 'react-native'; +import React, {Fragment} from 'react'; +import {ScrollView, StyleSheet, Text, View} from 'react-native'; +import {ProfilePreviewType} from '../../types'; import ExploreSectionUser from './ExploreSectionUser'; /** @@ -9,33 +10,40 @@ import ExploreSectionUser from './ExploreSectionUser'; interface ExploreSectionProps { title: string; - users: Array; + users: ProfilePreviewType[]; } const ExploreSection: React.FC = ({title, users}) => { - return ( + return users.length !== 0 ? ( {title} - {users.map((name, key) => ( - + + {users.map((user) => ( + ))} + ) : ( + ); }; const styles = StyleSheet.create({ container: { - marginBottom: 30, + marginVertical: '5%', }, header: { fontWeight: '600', fontSize: 20, color: '#fff', - marginBottom: 20, + marginLeft: '5%', + marginBottom: '5%', }, user: { - marginHorizontal: 15, + marginHorizontal: 5, + }, + padding: { + width: 10, }, }); diff --git a/src/components/search/ExploreSectionUser.tsx b/src/components/search/ExploreSectionUser.tsx index a9fce063..0bf68a20 100644 --- a/src/components/search/ExploreSectionUser.tsx +++ b/src/components/search/ExploreSectionUser.tsx @@ -1,12 +1,18 @@ -import React from 'react'; +import {useNavigation} from '@react-navigation/native'; +import React, {useEffect, useState} from 'react'; import { + Image, StyleSheet, Text, - ViewProps, - Image, TouchableOpacity, + ViewProps, } from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; +import {useDispatch, useSelector, useStore} from 'react-redux'; +import {loadAvatar} from '../../services'; +import {RootState} from '../../store/rootReducer'; +import {ProfilePreviewType, ScreenType} from '../../types'; +import {fetchUserX, userXInStore} from '../../utils'; /** * Search Screen for user recommendations and a search @@ -14,14 +20,52 @@ import LinearGradient from 'react-native-linear-gradient'; */ interface ExploreSectionUserProps extends ViewProps { - name: string; + user: ProfilePreviewType; } const ExploreSectionUser: React.FC = ({ - name, + user, style, }) => { + const {id, username, first_name, last_name} = user; + const [avatar, setAvatar] = useState(null); + const navigation = useNavigation(); + const {user: loggedInUser} = useSelector((state: RootState) => state.user); + const state: RootState = useStore().getState(); + const screenType = ScreenType.Search; + + const dispatch = useDispatch(); + + useEffect(() => { + let mounted = true; + const loadAvatarImage = async () => { + const response = await loadAvatar(id, true); + if (mounted) { + setAvatar(response); + } + }; + loadAvatarImage(); + return () => { + mounted = false; + }; + }, [user]); + + const handlePress = async () => { + if (!userXInStore(state, screenType, user.id)) { + await fetchUserX( + dispatch, + {userId: user.id, username: user.username}, + screenType, + ); + } + const userXId = loggedInUser.username === user.username ? undefined : id; + navigation.push('Profile', { + userXId, + screenType, + }); + }; + return ( - + = ({ angleCenter={{x: 0.5, y: 0.5}} style={styles.gradient}> - {name} - {`@${name.split(' ').join('')}`} + + {first_name} {last_name} + + {`@${username}`} ); }; @@ -42,27 +92,30 @@ const ExploreSectionUser: React.FC = ({ const styles = StyleSheet.create({ container: { alignItems: 'center', + width: 100, }, gradient: { - height: 80, - width: 80, + height: 60, + aspectRatio: 1, borderRadius: 40, justifyContent: 'center', alignItems: 'center', marginBottom: 10, }, profile: { - height: 76, - width: 76, + height: 55, + aspectRatio: 1, borderRadius: 38, }, name: { fontWeight: '600', + flexWrap: 'wrap', fontSize: 16, color: '#fff', + textAlign: 'center', }, username: { - fontWeight: '600', + fontWeight: '400', fontSize: 14, color: '#fff', }, -- cgit v1.2.3-70-g09d2