import { useEffect, useState, useRef, useMemo } from 'react'; import { Sidebar } from '../components/Sidebar'; import { VideoDetailModal } from '../components/VideoDetailModal'; import { useGenerationStore } from '../store/generation'; import type { GenerationTask } from '../types'; import styles from './AssetsPage.module.css'; function groupByDate(tasks: GenerationTask[]): { label: string; tasks: GenerationTask[] }[] { const now = new Date(); const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime(); const yesterday = today - 86400000; const groups = new Map(); const order: string[] = []; for (const task of tasks) { const d = new Date(task.createdAt); const dayStart = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); let label: string; if (dayStart >= today) { label = '今天'; } else if (dayStart >= yesterday) { label = '昨天'; } else { label = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; } if (!groups.has(label)) { groups.set(label, []); order.push(label); } groups.get(label)!.push(task); } return order.map((label) => ({ label, tasks: groups.get(label)! })); } function VideoThumbnail({ task, onClick, }: { task: GenerationTask; onClick: () => void; }) { const videoRef = useRef(null); const [hover, setHover] = useState(false); const handleEnter = () => { setHover(true); videoRef.current?.play().catch(() => {}); }; const handleLeave = () => { setHover(false); if (videoRef.current) { videoRef.current.pause(); videoRef.current.currentTime = 0; } }; const durationLabel = `00:${String(task.duration).padStart(2, '0')}`; return (
{task.resultUrl ? (