"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { Download, Trash2 } from "lucide-react"; import PageShell from "@/components/page-shell"; import { Button } from "@/components/ui/button"; import { ZenCard } from "@/components/ui/zen-card"; import BaziChartDisplay from "@/components/modes/bazi-chart"; import Markdown from "react-markdown"; import { buildHistoryMarkdown, deleteHistoryEntry, downloadMarkdown, loadHistory, } from "@/lib/history/storage"; import { MODE_LABELS, type CalcHistoryEntry } from "@/lib/history/types"; export default function HistoryPageClient() { const [items, setItems] = useState([]); const [activeId, setActiveId] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); useEffect(() => { let cancelled = false; (async () => { try { const list = await loadHistory(); if (cancelled) { return; } setItems(list); setActiveId(list[0]?.id ?? null); } catch (e) { if (!cancelled) { setError(e instanceof Error ? e.message : String(e)); } } finally { if (!cancelled) { setLoading(false); } } })(); return () => { cancelled = true; }; }, []); const active = items.find((e) => e.id === activeId) ?? null; async function handleDelete(id: string) { try { await deleteHistoryEntry(id); const next = items.filter((item) => item.id !== id); setItems(next); if (activeId === id) { setActiveId(next[0]?.id ?? null); } } catch (e) { setError(e instanceof Error ? e.message : String(e)); } } return (

测算历史

保存在服务器,按登录账号区分

{loading ? ( 加载中… ) : error ? ( {error} ) : items.length === 0 ? (

暂无测算记录

去六爻算卦
) : (
{items.map((item) => ( ))}
{active && (

问事:{active.question}

{active.summary && (

{active.summary}

)} {active.baziInput && (

出生:{active.baziInput.birthPlaceName} ·{" "} {active.baziInput.date}{" "} {active.baziInput.unknownHour ? "时辰不详" : active.baziInput.time}{" "} · {active.baziInput.gender === "male" ? "男" : "女"}

)} {active.baziChart && } {active.hexagram && (

{active.hexagram.guaTitle}

{active.hexagram.guaResult}

)}
{active.completion}
)}
)}
); }