// Author: fruit.com.cn import { Link } from 'react-router-dom'; import { useLocale } from '../../app/providers/AppProviders'; import { HistoryGridSkeleton } from '../../shared/components/skeletons'; import { useMutation } from '../../shared/hooks/useMutation'; import { useRequest } from '../../shared/hooks/useRequest'; import { normalizePage } from '../../shared/lib/pagination'; import { watchApi } from '../../shared/api/watch'; import { normalizeProgress } from '../../entities/drama/model'; function episodeLabel(record, localeCode) { if (!record.episodeNumber) return ''; return localeCode === 'zh' ? `第${record.episodeNumber}集` : `Episode ${record.episodeNumber}`; } export function HistoryPage() { const { locale } = useLocale(); const history = useRequest( ({ signal }) => watchApi.recent(1, 20, { signal }).then((payload) => normalizePage(payload).list.map((item) => normalizeProgress(item, locale.code))), [locale.code], ); const clearHistory = useMutation(() => watchApi.clear()); const records = history.data; const errorMessage = history.error?.message || clearHistory.error?.message || ''; const clearAll = async () => { if (!window.confirm(`${locale.clearHistory}?`)) return; try { await clearHistory.run(); history.refetch(); } catch { // 错误由 clearHistory.error 呈现 } }; return (

{locale.history}

{!!records?.length && }
{history.loading && records === null && } {errorMessage &&
{errorMessage}
} {records && !records.length && !errorMessage &&
{locale.historyEmpty}
} {!!records?.length && (
{records.map((record) => { const percent = Math.round(record.fraction * 100); const meta = [episodeLabel(record, locale.code), record.durationMs > 0 ? `${percent}%` : ''].filter(Boolean).join(' · '); return (
{record.title} {record.durationMs > 0 && } {record.title} {meta && {meta}}
); })}
)}
); }