"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { Trash2, ExternalLink } from "lucide-react"; import { bookmarks, SocialError, type Bookmark } from "@/lib/social"; import { useAuth } from "@/components/auth/auth-provider"; import { appendHighlight, hasHighlight } from "@/lib/text-highlight"; import { displaySourceLabel } from "@/lib/source-reference"; const FREE_LIMIT = 1; const PREMIUM_LIMIT = 5; export default function MyBookmarksPage() { const { user } = useAuth(); const [list, setList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { setLoading(true); bookmarks .list() .then((r) => setList(r ?? [])) .catch((err) => setError( err instanceof SocialError ? err.message : "Could not load bookmarks.", ), ) .finally(() => setLoading(false)); }, []); async function remove(id: string) { const prev = list; setList((rows) => rows.filter((b) => b.id !== id)); try { await bookmarks.delete(id); } catch (err) { setList(prev); setError(err instanceof SocialError ? err.message : "Could not delete."); } } const limit = user?.role === "admin" || user?.plan === "premium" ? PREMIUM_LIMIT : FREE_LIMIT; if (loading) return

Loading…

; return (
Bookmarks used:{" "} {list.length} / {limit} {user?.plan !== "premium" && list.length >= limit ? ( Upgrade to premium for 5 bookmarks ) : null}
{error ?

{error}

: null} {list.length === 0 ? (

No bookmarks yet. Select text anywhere and use “Add bookmark” in the more menu.

) : (
    {list.map((b) => { // If the stored URL doesn't already carry a `?hl=` (old data, or // a bookmark saved without a selection), synthesise one from the // excerpt so clicking still scrolls to + highlights the passage. const href = hasHighlight(b.source_url) || !b.excerpt ? b.source_url : appendHighlight(b.source_url, b.excerpt); return (
  • {displaySourceLabel(b.source_url, b.source_title)} {b.excerpt ? (

    “{b.excerpt}”

    ) : null}

    Saved {new Date(b.created_at).toLocaleDateString()}

  • ); })}
)}
); }