"use client"; import { useState } from "react"; import Link from "next/link"; import { UserAvatar } from "@/components/user-avatar"; import { ThoughtList } from "@/components/thought-list"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { ExternalLink, UserPlus, UserMinus } from "lucide-react"; import { followUser, unfollowUser, RemoteActor, Thought, Me } from "@/lib/api"; import { toast } from "sonner"; import { useAuth } from "@/hooks/use-auth"; interface RemoteUserProfileProps { actor: RemoteActor; initialPosts: Thought[]; me: Me | null; } export function RemoteUserProfile({ actor, initialPosts, me, }: RemoteUserProfileProps) { const [followed, setFollowed] = useState(false); const [loading, setLoading] = useState(false); const { token } = useAuth(); const handleFollow = async () => { if (!token) { toast.error("You must be logged in to follow users."); return; } setLoading(true); try { if (followed) { await unfollowUser(actor.handle, token); setFollowed(false); } else { await followUser(actor.handle, token); setFollowed(true); toast.success(`Follow request sent to ${actor.handle}`); } } catch { toast.error( followed ? "Failed to unfollow." : "Failed to send follow request.", ); } finally { setLoading(false); } }; const isOwnProfile = me?.username === actor.handle; const authorDetails = new Map(); initialPosts.forEach((t) => { authorDetails.set(t.author.username, { avatarUrl: actor.avatarUrl }); }); return (
{initialPosts.length > 0 ? ( ) : (

Posts are being fetched — check back soon.

)}
); }