|
| 1 | +import useCurrentUser from '@/hooks/useCurrentUser'; |
| 2 | +import useUser from '@/hooks/useUser'; |
| 3 | +import React, { useMemo } from 'react'; |
| 4 | +import { format } from 'date-fns'; |
| 5 | +import { BiCalendar } from 'react-icons/bi'; |
| 6 | +import Button from '../Button'; |
| 7 | + |
| 8 | +type Props = { |
| 9 | + userId: string; |
| 10 | +}; |
| 11 | + |
| 12 | +function UserBio({ userId }: Props) { |
| 13 | + const { data: currentUser } = useCurrentUser(); |
| 14 | + const { data: fetchedUser } = useUser(userId); |
| 15 | + const createdAt = useMemo(() => { |
| 16 | + if (!fetchedUser) return null; |
| 17 | + |
| 18 | + return format(new Date(fetchedUser.createdAt), 'MMMM yyyy'); |
| 19 | + }, [fetchedUser?.createdAt]); |
| 20 | + |
| 21 | + return ( |
| 22 | + <div className='border-b-[1px] border-neutral-800 pb-4'> |
| 23 | + <div className='flex justify-end p-2'> |
| 24 | + {currentUser?.id === userId ? ( |
| 25 | + <Button secondary label='Edit' onClick={() => {}} /> |
| 26 | + ) : ( |
| 27 | + <Button onClick={() => {}} label='Follow' secondary /> |
| 28 | + )} |
| 29 | + </div> |
| 30 | + <div className='mt-8 px-4'> |
| 31 | + <div className='flex flex-col'> |
| 32 | + <p className='text-white text-2xl font-semibold'>{fetchedUser?.name}</p> |
| 33 | + <p className='text-md text-neutral-500'>@{fetchedUser?.username}</p> |
| 34 | + </div> |
| 35 | + <div className='flex flex-col mt-4'> |
| 36 | + <p className='text-white'>{fetchedUser?.bio}</p> |
| 37 | + <div className='flex flex-row items-center gap-2 mt-4 text-neutral-500'> |
| 38 | + <BiCalendar /> |
| 39 | + <p>Joined {createdAt}</p> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + <div className='flex flex-row items-center mt-4 gap-6'> |
| 43 | + <div className='flex flex-row items-center gap-1'> |
| 44 | + <p className='text-white'>{fetchedUser?.followingIds?.length}</p> |
| 45 | + <p className='text-neutral-500'>Following</p> |
| 46 | + </div> |
| 47 | + <div className='flex flex-row items-center gap-1'> |
| 48 | + <p className='text-white'>{fetchedUser?.followersCount || 0}</p> |
| 49 | + <p className='text-neutral-500'>Followers</p> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +export default UserBio; |
0 commit comments