"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { loadStoryList, deleteStory } from "@/lib/clientStoryPersistence"; import type { StoryMeta } from "@/lib/db/repositories/storyRepo"; import { useLocalePath } from "@/lib/i18n/hooks"; export default function StoriesPage() { const lp = useLocalePath(); const [stories, setStories] = useState([]); const [loading, setLoading] = useState(true); const [deletingId, setDeletingId] = useState(null); useEffect(() => { loadStoryList() .then(setStories) .catch(() => setStories([])) .finally(() => setLoading(false)); }, []); const handleDelete = async (storyId: string) => { if (!confirm("确认删除这个剧情?此操作无法撤销。")) return; setDeletingId(storyId); const success = await deleteStory(storyId); if (success) { setStories((prev) => prev.filter((s) => s.id !== storyId)); } else { alert("删除失败,请稍后重试"); } setDeletingId(null); }; // D1 timestamps arrive as ISO strings over the JSON API boundary (the // server-side Date is serialized by NextResponse.json), so coerce before use. const formatDate = (value: Date | string | number) => { const date = value instanceof Date ? value : new Date(value); if (Number.isNaN(date.getTime())) return ""; const now = new Date(); const diff = now.getTime() - date.getTime(); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (days === 0) return "今天"; if (days === 1) return "昨天"; if (days < 7) return `${days} 天前`; return date.toLocaleDateString("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit" }); }; return (
{/* ================== HEADER ================== */}
InfiPlot 我 · 的 · 剧 · 情
{/* ================== CONTENT ================== */}
{loading ? (

载 · 入 · 中

) : stories.length === 0 ? (

还没有保存的剧情

回到首页开始新的故事
) : (
{stories.map((story) => (

{story.worldSetting.slice(0, 60)} {story.worldSetting.length > 60 ? "..." : ""}

{story.styleGuide}

{story.sceneCount} 幕 {formatDate(story.updatedAt)}
{/* Delete button */}
))}
)}
{/* ================== FOOTER ================== */}
MMXXVI {stories.length} 个剧情
); }