"use client" import { useEffect, useState } from "react" import { cn } from "@lib/utils" import { dmSansClassName, dmSans125ClassName } from "@/lib/fonts" import { Loader2, Mail, ThumbsUp, ThumbsDown, MoreHorizontal, } from "lucide-react" import { toast } from "sonner" import { SyncLogoIcon } from "@ui/assets/icons" import { analytics } from "@/lib/analytics" import { useDigests, useDigest, type DigestSummary } from "@/hooks/use-digests" interface DigestsViewProps { initialDigestId?: string | null } // feature → illustration (served from /images/digest/) const FEATURE_IMG: Record = { connections: "feat-router.png", chat: "feat-memory.png", extension: "feat-retrieval.png", plugins: "feat-profiles.png", mcp: "feat-router.png", search: "feat-retrieval.png", } const BRAIN_IMG = "https://supermemory.ai/images/brain-head.png" function formatIsoWeek(isoWeek: string): string { const match = isoWeek.match(/^(\d{4})-W(\d{2})$/) if (!match) return isoWeek const year = Number.parseInt(match[1] as string, 10) const week = Number.parseInt(match[2] as string, 10) const jan4 = new Date(year, 0, 4) const dow = jan4.getDay() || 7 const start = new Date(jan4) start.setDate(jan4.getDate() - dow + 1 + (week - 1) * 7) const end = new Date(start) end.setDate(start.getDate() + 6) const months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ] const sm = months[start.getMonth()] ?? "" const em = months[end.getMonth()] ?? "" return `${sm} ${start.getDate()}–${sm === em ? "" : `${em} `}${end.getDate()}, ${year}` } function isoWeekLabel(isoWeek: string): string { const m = isoWeek.match(/-W(\d{2})$/) return m ? `W${Number.parseInt(m[1] as string, 10)}` : isoWeek } // ─── Left list row ──────────────────────────────────────────────────────────── function DigestRow({ digest, featured, selected, onSelect, }: { digest: DigestSummary featured: boolean selected: boolean onSelect: () => void }) { return ( ) } // ─── Right pane: a single digest, faithful to the email layout ───────────────── function DigestContent({ digestId, isoWeek, }: { digestId: string isoWeek: string }) { const { data: digest, isLoading } = useDigest(digestId) const [rating, setRating] = useState<"up" | "down" | null>(null) const [showInput, setShowInput] = useState(false) const [message, setMessage] = useState("") // reset feedback state when switching digests useEffect(() => { setRating(null) setShowInput(false) setMessage("") analytics.digestViewed({ digest_id: digestId, iso_week: isoWeek }) }, [digestId, isoWeek]) if (isLoading) { return (
) } if (!digest) { return (
Digest not found.
) } const { digestData } = digest const rate = (r: "up" | "down") => { setRating(r) analytics.digestFeedback({ digest_id: digestId, iso_week: isoWeek, rating: r, }) } const submitDetail = () => { if (!message.trim()) return analytics.digestFeedbackDetail({ digest_id: digestId, iso_week: isoWeek, rating, message: message.trim(), }) setMessage("") setShowInput(false) toast.success("Thanks for the feedback!") } return (
{/* Header */}

Weekly digest · {formatIsoWeek(digest.isoWeek)}

{digestData.title || "Your week in Supermemory"}

{/* Greeting + intro, brain floated right */}

{digestData.intro}

{/* Highlights — numbered, no boxes */} {digestData.highlights.length > 0 && ( <>

This week's highlights

{digestData.highlights.map((h, i) => (
{String(i + 1).padStart(2, "0")}

{h.title}

{h.content}

))}
)} {/* Worth trying — the one place we use boxes (subtle) */} {digestData.featureRecommendations.length > 0 && (

Worth trying

{digestData.featureRecommendations.map((r) => (

{r.headline}

{r.body}{" "} {r.ctaLabel} →

))}
)} {/* Feedback */}
Was this digest useful?
{showInput && (