"use client"; import { useEffect, useState } from "react"; import { Plus } from "lucide-react"; import { collections, SocialError, type Collection } from "@/lib/social"; import { useAuth } from "@/components/auth/auth-provider"; import { CollectionViews } from "@/components/social/collection-views"; export default function MyCollectionsPage() { const { user } = useAuth(); const [list, setList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); // Inline create form const [showCreate, setShowCreate] = useState(false); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [isPublic, setIsPublic] = useState(true); const [creating, setCreating] = useState(false); useEffect(() => { setLoading(true); collections .mine() .then((r) => setList(r ?? [])) .catch((err) => setError( err instanceof SocialError ? err.message : "Could not load collections.", ), ) .finally(() => setLoading(false)); }, []); async function createOne(e: React.SyntheticEvent) { e.preventDefault(); if (!title.trim()) return; setCreating(true); setError(null); try { const c = await collections.create({ title, description: description || undefined, is_public: isPublic, }); setList((rows) => [c, ...rows]); setTitle(""); setDescription(""); setShowCreate(false); } catch (err) { setError(err instanceof SocialError ? err.message : "Could not create."); } finally { setCreating(false); } } const isPremium = user?.plan === "premium"; const publicCount = list.filter((c) => c.is_public).length; const privateCount = list.filter((c) => !c.is_public).length; return (

{isPremium ? ( <>Premium — unlimited collections. ) : ( <> {publicCount} / 5 public ·{" "} {privateCount} / 5 private )}

{!showCreate ? ( ) : null}
{showCreate ? (
setTitle(e.target.value)} placeholder="Collection title" maxLength={120} required className="w-full bg-background text-foreground text-base rounded-md border border-border px-3 py-2 outline-none focus-visible:ring-2 focus-visible:ring-primary/40" />