import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Checkbox } from '@/components/ui/checkbox' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { Progress } from '@/components/ui/progress' import { useCRUD, useSearch } from '@/hooks/data' import { useDialog } from '@/hooks/ui' import { useKV } from '@/hooks/use-kv' import { SearchBar } from '@/components/molecules/SearchBar' import { DataList, ActionButton, IconButton } from '@/components/atoms' import { Plus, Trash, Check, Clock } from '@phosphor-icons/react' import { toast } from 'sonner' import { cn } from '@/lib/utils' interface Todo { id: number text: string completed: boolean priority: 'low' | 'medium' | 'high' createdAt: string } export function ComprehensiveDemoPage() { const [todos, setTodos] = useKV('json-demo-todos', []) const crud = useCRUD({ items: todos, setItems: (updater) => setTodos(updater), }) const { query, setQuery, filtered } = useSearch({ items: todos, searchFields: ['text' as keyof Todo], }) const newTodoDialog = useDialog() const [newTodoText, setNewTodoText] = useState('') const [newTodoPriority, setNewTodoPriority] = useState<'low' | 'medium' | 'high'>('medium') const stats = { total: todos.length, completed: todos.filter(t => t.completed).length, pending: todos.filter(t => !t.completed).length, completionRate: todos.length > 0 ? (todos.filter(t => t.completed).length / todos.length) * 100 : 0, } const handleAddTodo = () => { if (newTodoText.trim()) { crud.create({ id: Date.now(), text: newTodoText, completed: false, priority: newTodoPriority, createdAt: new Date().toISOString(), }) setNewTodoText('') setNewTodoPriority('medium') newTodoDialog.close() toast.success('Task added successfully!') } } const handleToggleTodo = (id: number) => { const todo = todos.find(t => t.id === id) if (todo) { crud.update(id, { completed: !todo.completed }) toast.success(todo.completed ? 'Task marked as pending' : 'Task completed!') } } const handleDeleteTodo = (id: number) => { crud.delete(id) toast.success('Task deleted') } const getPriorityColor = (priority: string) => { switch (priority) { case 'high': return 'bg-red-500/10 text-red-600 border-red-500/20' case 'medium': return 'bg-yellow-500/10 text-yellow-600 border-yellow-500/20' case 'low': return 'bg-blue-500/10 text-blue-600 border-blue-500/20' default: return 'bg-gray-500/10 text-gray-600 border-gray-500/20' } } return (
{/* Header */}

Advanced Task Manager

Demonstrating atomic components, custom hooks, and reactive state management

{/* Stats Row */}

Total Tasks

{stats.total}

Completed

{stats.completed}

Pending

{stats.pending}

Completion

{Math.round(stats.completionRate)}%

{/* Main Content */}
Your Tasks Manage your tasks with advanced features
} label="Add Task" onClick={newTodoDialog.open} />
{/* Search */} {/* Task List */} (
handleToggleTodo(todo.id)} className="mt-1" />

{todo.text}

{todo.priority} {new Date(todo.createdAt).toLocaleDateString()}
} onClick={() => handleDeleteTodo(todo.id)} variant="ghost" title="Delete task" />
)} />
{/* Architecture Info */} Architecture Highlights What makes this demo special

Custom Hooks

useCRUD for data management, useSearch for filtering, useDialog for modals

Atomic Components

ActionButton, IconButton, DataList, SearchBar - all under 150 LOC

KV Persistence

All data persists between sessions using the Spark KV store

Reactive State

Computed stats update automatically when todos change

{/* Add Todo Dialog */} {newTodoDialog.isOpen && (
Add New Task Create a new task with priority
setNewTodoText(e.target.value)} placeholder="What needs to be done?" onKeyDown={(e) => e.key === 'Enter' && handleAddTodo()} autoFocus />
{(['low', 'medium', 'high'] as const).map((priority) => ( ))}
)}
) } // Missing import import { useState } from 'react'