import { useState, useEffect, useCallback } from "react"; import { Folder, Plus } from "lucide-react"; import { getCollections } from "../api/client"; import { useAuth } from "../context/AuthContext"; import CollectionModal from "../components/CollectionModal"; import CollectionRow from "../components/CollectionRow"; export default function Collections() { const { user } = useAuth(); const [collections, setCollections] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [isCreateModalOpen, setIsCreateModalOpen] = useState(false); const [editingCollection, setEditingCollection] = useState(null); const fetchCollections = useCallback(async () => { try { setLoading(true); const data = await getCollections(user.did); setCollections(data.items || []); } catch (err) { console.error(err); setError("Failed to load collections"); } finally { setLoading(false); } }, [user]); useEffect(() => { if (user) { fetchCollections(); } }, [user, fetchCollections]); const handleCreateSuccess = () => { fetchCollections(); setIsCreateModalOpen(false); setEditingCollection(null); }; if (loading) { return (
); } return (

Collections

Organize your annotations, highlights, and bookmarks

{error ? (
⚠️

Something went wrong

{error}

) : collections.length === 0 ? (

No collections yet

Create your first collection to start organizing your web annotations.

) : (
{collections.map((collection) => ( setEditingCollection(collection)} /> ))}
)} { setIsCreateModalOpen(false); setEditingCollection(null); }} onSuccess={handleCreateSuccess} collectionToEdit={editingCollection} />
); }