import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useAppContext } from '../context/AppContext'; type TaskItem = { id?: string; content?: string; priority?: string; status?: string; source?: string; due_at?: string; updated_at?: string; }; const Tasks: React.FC = () => { const { t } = useTranslation(); const { q } = useAppContext(); const [items, setItems] = useState([]); const [selected, setSelected] = useState(null); const [draft, setDraft] = useState({ id: '', content: '' }); const load = async () => { const r = await fetch(`/webui/api/tasks${q}`); if (!r.ok) return; const j = await r.json(); const arr = Array.isArray(j.items) ? j.items : []; setItems(arr); if (arr.length > 0) { setSelected(arr[0]); setDraft({ id: arr[0].id || '', content: arr[0].content || '' }); } }; useEffect(() => { load(); }, [q]); const save = async (action: 'create' | 'update' | 'delete') => { const payload: any = { action }; if (action === 'create') payload.item = draft; if (action === 'update') { payload.id = draft.id; payload.item = { id: draft.id, content: draft.content }; } if (action === 'delete') payload.id = draft.id; const r = await fetch(`/webui/api/tasks${q}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }); if (!r.ok) return; await load(); }; return (

{t('tasks')}

{t('taskList')}
{items.map((it, idx) => ( ))}
{t('taskCrud')}
setDraft({ ...draft, id: e.target.value })} placeholder="id" className="w-full px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded" />