From ab7fa09af967e0a8cf2ca53dfb24f8bc8a6886f7 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:37:32 -0700 Subject: [TMA 279] Ability to search and view someone's profile (#58) * Batch one : major changes * WIP checkpoint * The one before the final touch * Probable final touch * ran yarn lint D: * linter broke something * fixed a small bug * Addressed a small nitpick * Well abstracted now Co-authored-by: Ivan Chen --- src/components/common/AvatarTitle.tsx | 12 +++++++++--- src/components/profile/Avatar.tsx | 9 ++++++--- src/components/profile/Content.tsx | 24 +++++++++++++++--------- src/components/profile/Cover.tsx | 9 ++++++--- src/components/profile/ProfileBody.tsx | 9 ++++++--- src/components/profile/ProfileHeader.tsx | 14 ++++++++++---- src/components/search/SearchResult.tsx | 21 +++++++++++++++++---- src/components/taggs/Tagg.tsx | 10 +++++++--- src/components/taggs/TaggsBar.tsx | 11 +++++++++-- 9 files changed, 85 insertions(+), 34 deletions(-) (limited to 'src/components') diff --git a/src/components/common/AvatarTitle.tsx b/src/components/common/AvatarTitle.tsx index 8c82dca9..e9998113 100644 --- a/src/components/common/AvatarTitle.tsx +++ b/src/components/common/AvatarTitle.tsx @@ -2,13 +2,19 @@ import React from 'react'; import {Image, StyleSheet} from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import {AVATAR_DIM, AVATAR_GRADIENT_DIM, TAGGS_GRADIENT} from '../../constants'; -import {AuthContext} from '../../routes/authentication'; +import {AuthContext, ProfileContext} from '../../routes/'; /** * An image component that returns the of the icon for a specific social media platform. */ -const AvatarTitle: React.FC = () => { - const {avatar} = React.useContext(AuthContext); + +type AvatarTitleProps = { + isProfileView: boolean; +}; +const AvatarTitle: React.FC = ({isProfileView}) => { + const {avatar} = isProfileView + ? React.useContext(ProfileContext) + : React.useContext(AuthContext); return ( = ({style}) => { - const {avatar} = React.useContext(AuthContext); +const Avatar: React.FC = ({style, isProfileView}) => { + const {avatar} = isProfileView + ? React.useContext(ProfileContext) + : React.useContext(AuthContext); return ( ; + isProfileView: boolean; } -const Content: React.FC = ({y}) => { +const Content: React.FC = ({y, isProfileView}) => { const [profileBodyHeight, setProfileBodyHeight] = useState(0); const onLayout = (e: LayoutChangeEvent) => { const {height} = e.nativeEvent.layout; @@ -26,15 +28,19 @@ const Content: React.FC = ({y}) => { scrollEventThrottle={1} stickyHeaderIndices={[2, 4]}> - + - - - - {defaultMoments.map((title, index) => ( - - ))} - + + + {!isProfileView ? ( + + {defaultMoments.map((title, index) => ( + + ))} + + ) : ( + + )} ); }; diff --git a/src/components/profile/Cover.tsx b/src/components/profile/Cover.tsx index 01199f06..37ecb9bd 100644 --- a/src/components/profile/Cover.tsx +++ b/src/components/profile/Cover.tsx @@ -2,14 +2,17 @@ import React from 'react'; import {Image, StyleSheet} from 'react-native'; import Animated from 'react-native-reanimated'; import {IMAGE_WIDTH, COVER_HEIGHT} from '../../constants'; -import {AuthContext} from '../../routes/authentication'; +import {AuthContext, ProfileContext} from '../../routes/'; const {interpolate, Extrapolate} = Animated; interface CoverProps { y: Animated.Value; + isProfileView: boolean; } -const Cover: React.FC = ({y}) => { - const {cover} = React.useContext(AuthContext); +const Cover: React.FC = ({y, isProfileView}) => { + const {cover} = isProfileView + ? React.useContext(ProfileContext) + : React.useContext(AuthContext); const scale: Animated.Node = interpolate(y, { inputRange: [-COVER_HEIGHT, 0], outputRange: [1.5, 1.25], diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index e8d8de62..53b86708 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -1,15 +1,18 @@ import React from 'react'; import {StyleSheet, View, Text, LayoutChangeEvent} from 'react-native'; -import {AuthContext} from '../../routes/authentication'; +import {AuthContext, ProfileContext} from '../../routes/'; interface ProfileBodyProps { onLayout: (event: LayoutChangeEvent) => void; + isProfileView: boolean; } -const ProfileBody: React.FC = ({onLayout}) => { +const ProfileBody: React.FC = ({onLayout, isProfileView}) => { const { profile, user: {username}, - } = React.useContext(AuthContext); + } = isProfileView + ? React.useContext(ProfileContext) + : React.useContext(AuthContext); const {biography, website} = profile; return ( diff --git a/src/components/profile/ProfileHeader.tsx b/src/components/profile/ProfileHeader.tsx index ec382357..62c103fd 100644 --- a/src/components/profile/ProfileHeader.tsx +++ b/src/components/profile/ProfileHeader.tsx @@ -4,16 +4,22 @@ import Avatar from './Avatar'; import FollowCount from './FollowCount'; import {View, Text, StyleSheet} from 'react-native'; import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; -import {AuthContext} from '../../routes/authentication'; +import {AuthContext, ProfileContext} from '../../routes/'; -const ProfileHeader: React.FC = () => { +type ProfileHeaderProps = { + isProfileView: boolean; +}; + +const ProfileHeader: React.FC = ({isProfileView}) => { const { profile: {name}, - } = React.useContext(AuthContext); + } = isProfileView + ? React.useContext(ProfileContext) + : React.useContext(AuthContext); return ( - + {name} diff --git a/src/components/search/SearchResult.tsx b/src/components/search/SearchResult.tsx index 952f08f7..cc960308 100644 --- a/src/components/search/SearchResult.tsx +++ b/src/components/search/SearchResult.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useState, useContext} from 'react'; import {ProfilePreviewType} from '../../types'; import { View, @@ -8,10 +8,12 @@ import { ViewProps, TouchableOpacity, } from 'react-native'; +import {useNavigation} from '@react-navigation/native'; import RNFetchBlob from 'rn-fetch-blob'; import AsyncStorage from '@react-native-community/async-storage'; import {AVATAR_PHOTO_ENDPOINT} from '../../constants'; import {UserType} from '../../types'; +import {ProfileContext} from '../../routes/viewProfile'; const NO_USER: UserType = { userId: '', username: '', @@ -24,6 +26,8 @@ const SearchResult: React.FC = ({ profilePreview: {username, first_name, last_name, id}, style, }) => { + const navigation = useNavigation(); + const {loadProfile} = useContext(ProfileContext); const [avatarURI, setAvatarURI] = useState(null); const [user, setUser] = useState(NO_USER); useEffect(() => { @@ -38,7 +42,7 @@ const SearchResult: React.FC = ({ const response = await RNFetchBlob.config({ fileCache: true, appendExt: 'jpg', - }).fetch('GET', AVATAR_PHOTO_ENDPOINT + `${id}`, { + }).fetch('GET', AVATAR_PHOTO_ENDPOINT + `${id}/`, { Authorization: 'Token ' + token, }); const status = response.info().status; @@ -66,7 +70,7 @@ const SearchResult: React.FC = ({ * Cache maintains 10 recently searched users, popping off the oldest one if * needed to make space. */ - const addToRecentlyStored = async () => { + const addToRecentlyStoredAndNavigateToProfile = async () => { let user: ProfilePreviewType = { id, username, @@ -95,6 +99,15 @@ const SearchResult: React.FC = ({ } else { recentlySearchedList = [user]; } + + //Load user profile and navigate to ProfileView + //Load user profile makes sure that we actually load profile of the user the logged in user want to view + //Not sure if we should make this call before caching the search results ?? + loadProfile(user.id, user.username); + navigation.navigate('Profile', { + isProfileView: true, + }); + try { let recentlySearchedListString = JSON.stringify(recentlySearchedList); await AsyncStorage.setItem( @@ -111,7 +124,7 @@ const SearchResult: React.FC = ({ return ( = ({style}) => { +const Tagg: React.FC = ({style, isProfileView}) => { const navigation = useNavigation(); return ( @@ -14,6 +17,7 @@ const Tagg: React.FC = ({style}) => { onPress={() => navigation.navigate('SocialMediaTaggs', { socialMediaType: 'Instagram', + isProfileView: isProfileView, }) }> ; profileBodyHeight: number; + isProfileView: boolean; } -const TaggsBar: React.FC = ({y, profileBodyHeight}) => { +const TaggsBar: React.FC = ({ + y, + profileBodyHeight, + isProfileView, +}) => { const taggs: Array = []; for (let i = 0; i < 10; i++) { - taggs.push(); + taggs.push( + , + ); } const shadowOpacity: Animated.Node = interpolate(y, { inputRange: [ -- cgit v1.2.3-70-g09d2