'use client'; import { UserDto } from '@/app/types'; import { useUser } from '@clerk/nextjs'; import { useMutation, useQuery } from 'convex/react'; import Image from 'next/image'; import { AiFillCalendar } from 'react-icons/ai'; import { api } from '../../convex/_generated/api'; export default function UserProfile({ user }: { user: UserDto }) { const { isLoaded, isSignedIn, user: currentUser } = useUser(); const addFollow = useMutation(api.follows.addFollow); const removeFollow = useMutation(api.follows.removeFollow); const followerCount = useQuery(api.follows.getUserFollowerCount, { userId: user._id, }); const followingCount = useQuery(api.follows.getUserFollowingCount, { userId: user._id, }); const isFollowing = useQuery(api.follows.getFollowing, { followingId: user._id, }); const postCount = useQuery(api.posts.getUserPostCount, { userId: user._id }); const username = user.clerkUsername ?? user._id; const userCreatedDate = new Date(user._creationTime); const monthJoined = userCreatedDate.toLocaleString(undefined, { month: 'short', }); const yearJoined = userCreatedDate.getFullYear(); const countDataLoaded = postCount !== undefined && followerCount !== undefined && followingCount !== undefined; async function handleFollowButtonClick() { if (isFollowing) { await removeFollow({ followingId: user._id }); return; } await addFollow({ followingId: user._id }); } return (