// import { useState, useEffect, useRef } from "react" // import { motion, AnimatePresence } from "framer-motion" // import { ListOfTasks, 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" // import { Checkbox } from "@/components/ui/checkbox" // import { format } from "date-fns" // import { DatePicker } from "@/components/ui/date-picker" // interface TaskFormProps { // filter?: "today" | "upcoming" // } // export const TaskForm: React.FC = ({ filter }) => { // const [title, setTitle] = useState("") // const [dueDate, setDueDate] = useState(filter === "today" ? new Date() : undefined) // const [inputVisible, setInputVisible] = useState(false) // const { me } = useAccount({ root: {} }) // const inputRef = useRef(null) // const handleSubmit = (e: React.FormEvent) => { // e.preventDefault() // if (title.trim() && (filter !== "upcoming" || dueDate)) { // if (me?.root?.tasks === undefined) { // if (!me) return // me.root.tasks = ListOfTasks.create([], { owner: me }) // } // const newTask = Task.create( // { // title, // description: "", // status: "todo", // createdAt: new Date(), // updatedAt: new Date(), // dueDate: dueDate || null // }, // { owner: me._owner } // ) // me.root.tasks?.push(newTask) // resetForm() // } // } // const resetForm = () => { // setTitle("") // setDueDate(filter === "today" ? new Date() : undefined) // setInputVisible(false) // } // const handleKeyDown = (e: React.KeyboardEvent) => { // if (e.key === "Escape") { // resetForm() // } else if (e.key === "Backspace" && title.trim() === "") { // resetForm() // } // } // useEffect(() => { // if (inputVisible && inputRef.current) { // inputRef.current.focus() // } // }, [inputVisible]) // const formattedDate = dueDate ? format(dueDate, "EEE, MMMM do, yyyy") : "Select a date" // return ( //
// // {!inputVisible ? ( // // // // ) : ( // //
// {}} /> // setTitle(e.target.value)} // onKeyDown={handleKeyDown} // placeholder="Task title" // /> //
//
// {filter === "upcoming" && ( // setDueDate(date)} /> // )} // {formattedDate} //
//
// )} //
//
// ) // } import { useState, useEffect, useRef } from "react" import { motion, AnimatePresence } from "framer-motion" import { ListOfTasks, 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" import { Checkbox } from "@/components/ui/checkbox" import { format } from "date-fns" import { DatePicker } from "@/components/ui/date-picker" interface TaskFormProps { filter?: "today" | "upcoming" | undefined } export const TaskForm: React.FC = ({ filter }) => { const [title, setTitle] = useState("") const [dueDate, setDueDate] = useState(filter === "today" ? new Date() : undefined) const [inputVisible, setInputVisible] = useState(false) const { me } = useAccount({ root: {} }) const inputRef = useRef(null) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (title.trim() && (filter === "today" || (filter === "upcoming" && dueDate))) { if (me?.root?.tasks === undefined) { if (!me) return me.root.tasks = ListOfTasks.create([], { owner: me }) } const newTask = Task.create( { title, description: "", status: "todo", createdAt: new Date(), updatedAt: new Date(), dueDate: dueDate || (filter === "today" ? new Date() : null) }, { owner: me._owner } ) me.root.tasks?.push(newTask) resetForm() } } const resetForm = () => { setTitle("") setDueDate(filter === "today" ? new Date() : undefined) setInputVisible(false) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Escape") { resetForm() } else if (e.key === "Backspace" && title.trim() === "") { resetForm() } } useEffect(() => { if (inputVisible && inputRef.current) { inputRef.current.focus() } }, [inputVisible]) const formattedDate = dueDate ? format(dueDate, "EEE, MMMM do, yyyy") : "Select a date" return (
{filter ? ( !inputVisible ? ( ) : (
{}} /> setTitle(e.target.value)} onKeyDown={handleKeyDown} placeholder="Task title" />
{filter === "upcoming" && ( setDueDate(date)} /> )} {formattedDate}
) ) : null}
) }