"use client" import { useState, useEffect, useRef } from "react" import { motion, AnimatePresence } from "framer-motion" import { Task } from "@/lib/schema/tasks" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { useAccount } from "@/lib/providers/jazz-provider" import { LaIcon } from "@/components/custom/la-icon" interface TaskFormProps { onAddTask: (task: Task) => void } export const TaskForm: React.FC = ({ onAddTask }) => { const [title, setTitle] = useState("") const [inputVisible, setInputVisible] = useState(false) const { me } = useAccount() const inputRef = useRef(null) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (title.trim() && me) { const newTask = Task.create( { title, description: "", status: "todo", createdAt: new Date(), updatedAt: new Date() }, { owner: me._owner } ) onAddTask(newTask) resetForm() } } const resetForm = () => { setTitle("") setInputVisible(false) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Escape") { resetForm() } } useEffect(() => { if (inputVisible && inputRef.current) { inputRef.current.focus() } }, [inputVisible]) return (
{!inputVisible ? ( ) : ( setTitle(e.target.value)} onKeyDown={handleKeyDown} placeholder="Enter task title" /> )}
) }