-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7a298c
commit e29bc29
Showing
8 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useLocalSearchParams } from 'expo-router'; | ||
import { useUserById } from '../../../hooks/user'; | ||
import { LinearGradient } from 'expo-linear-gradient'; | ||
import { | ||
View, | ||
Text, | ||
Dimensions, | ||
TouchableOpacity, | ||
TextInput, | ||
Image, | ||
FlatList, | ||
} from 'react-native'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
withTiming, | ||
Easing, | ||
} from 'react-native-reanimated'; | ||
import { UserType } from '../../../types/userProfile'; | ||
import ProfileTags from '../../../components/profile_tag'; | ||
|
||
const FollowerFollowing = () => { | ||
const { width } = Dimensions.get('window'); | ||
const { id, option } = useLocalSearchParams<{ id: string; option: string }>(); | ||
const { data, isError, isLoading } = useUserById(id); | ||
const [category, setCategory] = | ||
option == 'followers' ? useState('Followers') : useState('Following'); | ||
const [userData, setUserData] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
const findData = () => { | ||
if (category == 'Followers') { | ||
setUserData(data?.user.followers); | ||
} else { | ||
setUserData(data?.user.following); | ||
} | ||
}; | ||
findData(); | ||
}, [category]); | ||
|
||
const renderUser = ({ item }: { item: any }) => ( | ||
<View className="mb-2 w-[80vw]"> | ||
<ProfileTags id={item} /> | ||
</View> | ||
); | ||
|
||
const indicatorStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ | ||
translateX: withTiming(category === 'Followers' ? 0 : width / 2, { | ||
duration: 300, | ||
easing: Easing.bezier(0.25, 0.1, 0.25, 1), | ||
}), | ||
}, | ||
], | ||
}; | ||
}, [category]); | ||
|
||
return ( | ||
<LinearGradient | ||
colors={['#549ac7', '#ffffff', '#ffffff', '#ffffff']} | ||
style={{ flex: 1 }} | ||
> | ||
<View className="flex flex-col items-center mt-[10vh] "> | ||
<Text className="font-bold text-darkblue text-xl"> | ||
{category === 'Followers' ? 'Followers' : 'Following'} | ||
</Text> | ||
<Text className="font-bold text-darkblue text-md mt-[2vh]"> | ||
@{data?.user.username} | ||
</Text> | ||
|
||
<View className="flex w-100 flex-row pb-[5%] pt-[2vh]"> | ||
<Animated.View | ||
className="bg-[#3788BE] absolute h-[1px] w-2/5 mx-5" | ||
style={[ | ||
{ | ||
bottom: '30%', | ||
}, | ||
indicatorStyle, | ||
]} | ||
/> | ||
<TouchableOpacity | ||
className="py-2 w-[50%] justify-center items-center" | ||
onPress={() => setCategory('Followers')} | ||
> | ||
<Text | ||
className={`font-bold text-base text-sm ${ | ||
category === 'Followers' ? 'text-[#3788BE]' : 'text-gray-400' | ||
}`} | ||
> | ||
{data.user.followers.length} Followers | ||
</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity | ||
className="py-[3%] w-[50%] justify-center items-center" | ||
onPress={() => setCategory('Following')} | ||
> | ||
<Text | ||
className={`font-bold text-base text-sm ${ | ||
category === 'Following' ? 'text-[#3788BE]' : 'text-gray-400' | ||
}`} | ||
> | ||
{data.user.following.length} Following | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
|
||
<FlatList data={userData} renderItem={renderUser}></FlatList> | ||
</View> | ||
</LinearGradient> | ||
); | ||
}; | ||
|
||
export default FollowerFollowing; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { View, Text, TouchableOpacity } from 'react-native'; | ||
import Profile from './profile'; | ||
import { router } from 'expo-router'; | ||
import { PROFILE_PHOTO } from '../consts/profile'; | ||
import FollowButton from '../app/(app)/user/components/follow-button'; | ||
import useFollow from '../hooks/following'; | ||
import { UserType } from '../types/userProfile'; | ||
import { useUserById } from '../hooks/user'; | ||
import { useAuthStore } from '../auth/authStore'; | ||
|
||
interface ProfileTagProps { | ||
id: string; | ||
} | ||
const ProfileTags: React.FC<ProfileTagProps> = ({ id }) => { | ||
const { data, isLoading, isError } = useUserById(id); | ||
const { handleFollowToggle, isFollowing, isPending } = useFollow( | ||
data?.user._id, | ||
); | ||
const uri = data?.user.profilePicture | ||
? data?.user.profilePicture | ||
: PROFILE_PHOTO; | ||
const { mongoDBId } = useAuthStore(); | ||
const isViewingOwnProfile = mongoDBId === id; | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
router.push(`/user/${data?.user._id}`); | ||
}} | ||
className="flex w-full flex-row items-center h-[8vh] bg-white shadow-sm rounded-lg pl-2" | ||
> | ||
<Profile image={uri} size="md" /> | ||
<View className="flex flex-col pl-2"> | ||
<Text>{data?.user.username}</Text> | ||
</View> | ||
|
||
{isViewingOwnProfile ? ( | ||
<></> | ||
) : ( | ||
<View className="absolute left-[58vw] w-[60vw]"> | ||
<FollowButton | ||
onPress={handleFollowToggle} | ||
isPending={isPending!} | ||
isFollowing={isFollowing} | ||
/> | ||
</View> | ||
)} | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
export default ProfileTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export type UpdateProfileFields = { | ||
profilePicture: string; //String to the s3 | ||
}; | ||
|
||
export type UserType = { | ||
_id: string; | ||
profilePicture: string; | ||
username: string; | ||
}; |