"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { readProgress, type ReadingProgress } from "@/lib/progress"; type ChapterLite = { number: number; title: string; }; type Props = { mangaSlug: string; chapters: ChapterLite[]; }; export { readProgress, writeProgress } from "@/lib/progress"; export type { ReadingProgress } from "@/lib/progress"; export function ReadingProgressButton({ mangaSlug, chapters }: Props) { const [progress, setProgress] = useState(null); useEffect(() => { setProgress(readProgress(mangaSlug)); }, [mangaSlug]); if (chapters.length === 0) return null; const first = chapters[0]; const resumeChapter = progress !== null ? chapters.find((c) => c.number === progress.chapter) : null; const target = resumeChapter ?? first; const href = resumeChapter ? `/manga/${mangaSlug}/${target.number}?resume=1` : `/manga/${mangaSlug}/${target.number}`; return ( {resumeChapter ? ( <> 继续阅读 · #{resumeChapter.number} {resumeChapter.title} ) : ( "开始阅读" )} ); }