"use client"; /** * ProfileHeader — Instagram-style centered header used at the top of * /u/me and /u/[handle]. Avatar, display name, @handle, a single stat * line, and an action row. * * The action row hosts: * • "Edit profile" link — only on the owner's own profile (via the * `editHref` prop set by /u/me layout). * • Reading-settings gear — also owner-only. We use `editHref` as the * "is this my profile?" signal (the /u/me layout passes it; the * /u/[handle] layout does not), so the two buttons stay in lockstep * and visitors on someone else's profile see a clean row with no * personal-settings affordances. The gear links to /settings (the * dedicated settings page) rather than opening a popover — * centred-row popovers tend to spill off the left edge on narrow * viewports. * * Clicking the avatar (when there's an uploaded image) opens a portal * modal showing the full-size image inside a circular crop. Tap the * backdrop or press Escape to close. * * Auth users on someone else's profile reach reading settings via the * sidebar rail on desktop. Anonymous visitors use SiteHeader's mobile * gear. */ import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import Image from "next/image"; import Link from "next/link"; import { Settings, X } from "lucide-react"; import { cn } from "@/lib/utils"; export function ProfileHeader({ avatarURL, name, handle, postCount, joinedAt, editHref, }: { avatarURL: string | null; name: string; handle: string; postCount?: number; joinedAt?: string; /** When provided, shows an "Edit profile" CTA below the handle AND * the reading-settings gear. Acts as the canonical "this is my own * profile" signal across the action row. */ editHref?: string; }) { // Both action-row affordances are owner-only and ride on the same // `editHref` signal — when it's absent we render no action row at // all, which keeps visitor profile views clean. const showReadingSettings = !!editHref; const showActions = !!editHref; const [zoomOpen, setZoomOpen] = useState(false); return ( <>
setZoomOpen(true) : undefined} />

{name}

@{handle}

{typeof postCount === "number" || joinedAt ? (

{typeof postCount === "number" ? ( <> {postCount} post {postCount === 1 ? "" : "s"} ) : null} {typeof postCount === "number" && joinedAt ? " · " : null} {joinedAt ? <>Joined {new Date(joinedAt).toLocaleDateString()} : null}

) : null}
{showActions ? (
{editHref ? ( Edit profile ) : null} {showReadingSettings ? ( ) : null}
) : null}
{avatarURL ? ( setZoomOpen(false)} /> ) : null} ); } function Avatar({ src, name, onZoom, }: { src: string | null; name: string; /** Provided when the avatar should be interactive — the parent shows * the zoom modal on click. Omit (or pass undefined) to render the * initials placeholder as a plain non-clickable element. */ onZoom?: () => void; }) { if (src) { return ( ); } const initials = name .split(/\s+/) .map((p) => p[0]) .slice(0, 2) .join("") .toUpperCase() || "?"; return (
{initials}
); } /** * AvatarZoomModal — portaled full-screen overlay with the avatar shown * inside a large circular crop. Click the backdrop or press Escape to * close. Body scroll is locked while open so the page underneath * doesn't jitter when the modal mounts. */ function AvatarZoomModal({ src, name, open, onClose, }: { src: string; name: string; open: boolean; onClose: () => void; }) { useEffect(() => { if (!open) return; function onKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [open, onClose]); useEffect(() => { if (!open) return; const prev = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.body.style.overflow = prev; }; }, [open]); if (!open || typeof document === "undefined") return null; return createPortal(
{/* Stop-propagation so clicks on the image itself don't dismiss the modal — only the surrounding backdrop closes. */}
e.stopPropagation()} className="relative rounded-full overflow-hidden ring-1 ring-white/20 shadow-2xl" style={{ // Square box capped at 80% of the smaller viewport dimension — // keeps the circle large but always fully visible with a // comfortable margin on tiny screens. width: "min(80vw, 80vh, 28rem)", height: "min(80vw, 80vh, 28rem)", }} > {name}
, document.body, ); }