import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { api } from '../api/client'; import { useAuth } from '../lib/auth'; import { Button, PageHeader, EmptyState } from '../components/ui'; import { IconImage, IconBack } from '../components/icons'; import type { Photo } from '../types'; type Candidate = Photo & { modelCode: string; category: string }; export function AdminPhotosPage() { const { user } = useAuth(); const [items, setItems] = useState([]); const [busy, setBusy] = useState(false); const isAdmin = user?.role === 'admin'; const load = () => api.candidatePhotos().then(setItems).catch(() => {}); useEffect(() => { if (isAdmin) load(); }, [isAdmin]); if (!user) { return (

请先登录。

返回首页
); } if (!isAdmin) { return (

仅管理员可访问候选审图。

返回首页
); } const confirm = async (pid: number) => { await api.confirmPhoto(pid).catch(() => {}); setItems((xs) => xs.filter((x) => x.id !== pid)); }; const remove = async (pid: number) => { await api.deletePhoto(pid).catch(() => {}); setItems((xs) => xs.filter((x) => x.id !== pid)); }; const confirmAll = async () => { setBusy(true); for (const it of items) await api.confirmPhoto(it.id).catch(() => {}); setBusy(false); load(); }; return (
0 ? ( ) : undefined } /> {items.length === 0 ? ( } text="没有待确认的候选照片。可在本机运行 npm run fetch-images 灌入候选。" /> ) : (
{items.map((p) => (
{p.modelCode}
{p.modelCode} {p.category} © {p.author || '未署名'} {p.license ? ` · ${p.license}` : ''} {p.sourceUrl ? ( <> {' · '} 来源 ) : null}
))}
)}
); }