"use client"; import { useState } from "react"; import { useTheme } from "next-themes"; import { Pencil, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { MDEditor, MarkdownPreview } from "@/components/markdown/markdown-widgets"; import { useBoard } from "@/components/board/board-context"; import type { TodoDTO } from "@/types/board"; const TITLE_MAX = 20; export function TodoEditDialog({ todo, groupId, categoryId, open, onOpenChange, }: { todo: TodoDTO; groupId: string; categoryId: string; open: boolean; onOpenChange: (open: boolean) => void; }) { const { editTodo, removeTodo } = useBoard(); const { resolvedTheme } = useTheme(); const colorMode = resolvedTheme === "dark" ? "dark" : "light"; const [title, setTitle] = useState(todo.title); const [details, setDetails] = useState(todo.details ?? ""); // Details gets its own view/edit toggle, same as the group's Notes // editor -- markdown renders as a preview until you choose to edit it, // rather than always showing raw source in a plain textarea. const [editingDetails, setEditingDetails] = useState(false); const [pending, setPending] = useState(false); function handleOpenChange(next: boolean) { if (next) { setTitle(todo.title); setDetails(todo.details ?? ""); setEditingDetails(false); } onOpenChange(next); } async function handleSave() { const trimmed = title.trim(); if (!trimmed) return; setPending(true); const ok = await editTodo(todo.id, groupId, categoryId, { title: trimmed, details: details.trim() || null, }); setPending(false); if (ok) onOpenChange(false); } async function handleDelete() { setPending(true); await removeTodo(todo.id, groupId, categoryId); setPending(false); onOpenChange(false); } return ( Edit to-do
setTitle(e.target.value)} />

{title.length}/{TITLE_MAX}

{editingDetails ? ( setDetails(v ?? "")} height={220} /> ) : details ? (
) : (

No details yet. Click Edit to add some -- links, lists, etc.

)}
); }