import { useState } from 'react'; import { useUser } from '../context/UserContext'; import { useProject } from '../context/ProjectContext'; import { api } from '../api/client'; interface LocalTask { id: string; title: string; description: string; } export function TaskSetupPage({ onComplete }: { onComplete: () => void }) { const { user, logout } = useUser(); const { currentProject, clearProject } = useProject(); const [tasks, setTasks] = useState([]); // Manual form state const [manualTitle, setManualTitle] = useState(''); const [manualDescription, setManualDescription] = useState(''); // Edit state const [editingId, setEditingId] = useState(null); const [editTitle, setEditTitle] = useState(''); const [editDescription, setEditDescription] = useState(''); const [isGenerating, setIsGenerating] = useState(false); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(''); const [saveProgress, setSaveProgress] = useState({ current: 0, total: 0 }); const handleLogout = () => { clearProject(); logout(); }; const generateId = () => Math.random().toString(36).substring(2, 9); const handleAddManualTask = () => { if (!manualTitle.trim()) return; setTasks([ ...tasks, { id: generateId(), title: manualTitle.trim(), description: manualDescription.trim(), }, ]); setManualTitle(''); setManualDescription(''); }; const handleGenerateTasks = async () => { if (!currentProject) return; setIsGenerating(true); setError(''); try { const result = await api.generateTasks(currentProject.id, 50); const newTasks = result.tasks.map((t) => ({ id: generateId(), title: t.title, description: t.description, })); setTasks([...tasks, ...newTasks]); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to generate tasks'); } finally { setIsGenerating(false); } }; const handleDeleteTask = (id: string) => { setTasks(tasks.filter((t) => t.id !== id)); }; const handleStartEdit = (task: LocalTask) => { setEditingId(task.id); setEditTitle(task.title); setEditDescription(task.description); }; const handleSaveEdit = () => { if (!editingId) return; setTasks( tasks.map((t) => t.id === editingId ? { ...t, title: editTitle.trim(), description: editDescription.trim() } : t ) ); setEditingId(null); setEditTitle(''); setEditDescription(''); }; const handleCancelEdit = () => { setEditingId(null); setEditTitle(''); setEditDescription(''); }; const handleSaveAndContinue = async () => { if (tasks.length === 0 || !currentProject) return; setIsSaving(true); setError(''); setSaveProgress({ current: 0, total: tasks.length }); try { for (let i = 0; i < tasks.length; i++) { const task = tasks[i]; await api.createTask(currentProject.id, { title: task.title, description: task.description, }); setSaveProgress({ current: i + 1, total: tasks.length }); } onComplete(); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to save tasks'); } finally { setIsSaving(false); } }; const handleClearAll = () => { setTasks([]); }; if (!user || !currentProject) return null; return (
{/* Header */}

Project Memory

| {currentProject.name}
{user.firstName} ({user.id})
{/* Main Content */}
{/* Page Title */}

Set Up Tasks

Add tasks manually or generate demo tasks with AI (max 50)

{/* Error Display */} {error && (
{error}
)} {/* Two Column Layout */}
{/* Left Column - Add Tasks */}
{/* Manual Add */}

Add Task

setManualTitle(e.target.value)} placeholder="Task title" className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white placeholder-white/40 focus:outline-none focus:ring-2 focus:ring-purple-500 text-sm" onKeyDown={(e) => e.key === 'Enter' && handleAddManualTask()} />