"use client"; import { Calendar, MessageCircle, Share2, User as UserIcon, } from "lucide-react"; import Link from "next/link"; import * as React from "react"; import { toast } from "sonner"; import { ContentList } from "@/components/content-list"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { useAuth } from "@/providers/auth-provider"; import { ContentService } from "@/services/content.service"; import { UserService } from "@/services/user.service"; import type { User } from "@/types/user"; export default function PublicProfilePage({ params, }: { params: Promise<{ username: string }>; }) { const { username } = React.use(params); const { user: currentUser, isAuthenticated } = useAuth(); const [user, setUser] = React.useState(null); const [loading, setLoading] = React.useState(true); const isOwnProfile = currentUser?.username === username; React.useEffect(() => { UserService.getProfile(username) .then(setUser) .catch(console.error) .finally(() => setLoading(false)); }, [username]); const fetchUserMemes = React.useCallback( (params: { limit: number; offset: number }) => ContentService.getExplore({ ...params, author: username }), [username], ); const handleShareProfile = () => { const url = `${window.location.origin}/user/${username}`; navigator.clipboard.writeText(url); toast.success("Lien du profil copié !"); }; if (loading) { return (
); } if (!user) { return (

Utilisateur non trouvé

Le membre @{username} n'existe pas ou a quitté le troupeau.

); } return (
{user.username.slice(0, 2).toUpperCase()}

{user.displayName || user.username}

@{user.username}

{user.bio && (

{user.bio}

)}
Membre depuis{" "} {new Date(user.createdAt).toLocaleDateString("fr-FR", { month: "long", year: "numeric", })}
{!isOwnProfile && isAuthenticated && ( )}

Ses mèmes

); }