"use client"; import { useEffect, useState } from "react"; import { ExternalLink, Send } from "lucide-react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { EmptyState } from "@/components/layout/empty-state"; import { PageHeader } from "@/components/layout/page-header"; import { notify } from "@/lib/notifications/store"; interface PublishedItem { id: string; text: string; angle?: string | null; hook?: string | null; permalink?: string | null; publishedAt: string; views?: number | null; likes?: number | null; replies?: number | null; } export default function PublishedPage() { const [items, setItems] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/published") .then(async (r) => { const data = await r.json(); if (!r.ok) { throw new Error(data.error ?? "無法載入已發布貼文"); } setItems(data.published ?? []); }) .catch((error) => { notify({ type: "error", title: "載入失敗", message: error instanceof Error ? error.message : "請稍後再試", }); }) .finally(() => setLoading(false)); }, []); return (
{loading ? (
{[0, 1].map((i) => (
))}
) : items.length === 0 ? ( ) : (
{items.map((item, i) => ( {item.angle ?? "已發布貼文"} {new Date(item.publishedAt).toLocaleString("zh-TW")} {item.permalink && ( 查看貼文 )} {item.hook && (

{item.hook}

)}

{item.text}

{(item.views != null || item.likes != null || item.replies != null) && (
{item.views != null && 瀏覽 {item.views}} {item.likes != null && 讚 {item.likes}} {item.replies != null && 留言 {item.replies}}
)}
))}
)}
); }