'use client'; // 管理后台 - 友情链接管理 import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { API } from '@/lib/api'; import { Icon } from '../Icons'; import { useToast } from '../Toast'; export default function AdminLinks() { const { t } = useTranslation(); const { toast, confirmAction } = useToast(); const [links, setLinks] = useState([]); const [title, setTitle] = useState(''); const [url, setUrl] = useState(''); const load = () => { API.getLinks().then(setLinks).catch(() => {}); }; useEffect(load, []); const handleAdd = async () => { if (!title.trim() || !url.trim()) { toast(t('admin.link.incomplete'), 'warning'); return; } try { await API.addLink(title.trim(), url.trim()); setTitle(''); setUrl(''); load(); } catch (err) { toast(t('admin.link.addFailed', { msg: err.message }), 'error'); } }; const handleDelete = async (id) => { if (!await confirmAction(t('admin.link.confirmDelete'))) return; try { await API.deleteLink(id); load(); } catch (err) { toast(t('admin.common.deleteFailed', { msg: err.message }), 'error'); } }; return ( <>
setTitle(e.target.value)} /> setUrl(e.target.value)} />
); }