import { useCallback } from 'react'
import { useValue } from 'tldraw'
import { TodoItem } from '../../shared/types/TodoItem'
import { TldrawAgent } from '../agent/TldrawAgent'
export function TodoList({ agent }: { agent: TldrawAgent }) {
const todoItems = useValue('todoList', () => agent.todos.getTodos(), [agent])
if (todoItems.length === 0) {
return null
}
return (
{todoItems.map((item) => (
))}
)
}
function TodoListItem({ item, agent }: { item: TodoItem; agent: TldrawAgent }) {
const deleteTodo = useCallback(() => {
agent.todos.delete([item.id])
}, [item.id, agent])
const getStatusIcon = (status: TodoItem['status']) => {
switch (status) {
case 'todo':
return '○'
case 'in-progress':
return '➤'
case 'done':
return '●'
}
}
const icon = getStatusIcon(item.status)
return (
{icon}
{item.text}
)
}