'use client' import { useEffect, useState } from 'react' import { CheckSquare, Plus, Tag, Clock, User, Check, X, ChevronRight, RefreshCw } from 'lucide-react' interface Task { task_id: string; title: string; description?: string; priority: string tags?: string; skills?: string; _status: string; posted_at?: string claimed_by?: string; claimed_at?: string; completed_at?: string; result?: string } const PRIORITY_COLORS: Record = { high: '#ef4444', critical: '#FF1D6C', normal: '#2979FF', low: '#888' } const STATUS_COLORS: Record = { available: '#22c55e', claimed: '#F5A623', completed: '#9C27B0' } function timeAgo(iso?: string) { if (!iso) return '—' try { const diff = Date.now() - new Date(iso).getTime() const m = Math.floor(diff / 60000), h = Math.floor(m / 60), d = Math.floor(h / 24) if (d > 0) return `${d}d ago`; if (h > 0) return `${h}h ago`; if (m > 0) return `${m}m ago`; return 'just now' } catch { return '—' } } export default function TasksPage() { const [tasks, setTasks] = useState([]) const [counts, setCounts] = useState({ available: 0, claimed: 0, completed: 0 }) const [filter, setFilter] = useState('all') const [loading, setLoading] = useState(true) const [adding, setAdding] = useState(false) const [form, setForm] = useState({ title: '', description: '', priority: 'normal', tags: '', skills: '' }) const [saving, setSaving] = useState(false) const load = () => { setLoading(true) fetch(`/api/tasks?status=${filter}`).then(r => r.json()).then(d => { setTasks(d.tasks || []) setCounts(d.counts || {}) setLoading(false) }).catch(() => setLoading(false)) } useEffect(() => { load() }, [filter]) const createTask = async () => { if (!form.title) return setSaving(true) await fetch('/api/tasks', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'create', ...form }) }) setSaving(false); setAdding(false); setForm({ title: '', description: '', priority: 'normal', tags: '', skills: '' }); load() } const claimTask = async (id: string) => { await fetch('/api/tasks', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'claim', task_id: id, assigned_to: 'web-ui' }) }) load() } const completeTask = async (id: string) => { const result = prompt('Result / summary:') || '' await fetch('/api/tasks', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'complete', task_id: id, result }) }) load() } const tabs = ['all', 'available', 'claimed', 'completed'] return (

Task Marketplace

{counts.available} available · {counts.claimed} claimed · {counts.completed} completed

{/* Filter tabs */}
{tabs.map(t => ( ))}
{/* Add form */} {adding && (

Create Task

setForm(f => ({ ...f, title: e.target.value }))} placeholder="Task title *" style={{ background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.1)', borderRadius: 8, padding: '9px 12px', color: '#fff', fontSize: 13, outline: 'none' }} />