diff --git a/src/components/ListItem.tsx b/src/components/ListItem.tsx index e139b91..b037161 100644 --- a/src/components/ListItem.tsx +++ b/src/components/ListItem.tsx @@ -5,10 +5,12 @@ import { useRef, useEffect, } from "react" -import { FileText } from "lucide-react" + +import { FileText, X } from "lucide-react" import { Input } from "@/components/ui/input" import { cn } from "@/lib/utils" import { useNotesStore } from "../contexts/NotesStore" +import { useNote } from "@/contexts/ActiveNoteContext" type ListItemProps = { id: string @@ -17,7 +19,8 @@ type ListItemProps = { } function ListItem({ id, label, onSelect }: ListItemProps) { - const { updateNote } = useNotesStore() + const { updateNote, deleteNote } = useNotesStore(); + const { currentNoteId, setCurrentNoteId } = useNote(); const [tempLabel, setTempLabel] = useState(label) const [isEditing, setIsEditing] = useState(false) const containerRef = useRef(null) @@ -45,6 +48,14 @@ function ListItem({ id, label, onSelect }: ListItemProps) { setIsEditing(false) } + const handleDelete = () => { + if (currentNoteId === id) { + setCurrentNoteId(null) + } + + deleteNote(id) + } + useEffect(() => { if (!isEditing) return @@ -70,10 +81,10 @@ function ListItem({ id, label, onSelect }: ListItemProps) { className={cn( "flex items-center gap-2 px-3 py-2 rounded-md cursor-pointer", "text-muted-foreground hover:bg-muted hover:text-foreground", - "transition-colors" + "transition-colors listItem" )} > - + {isEditing ? ( ) : ( - {label} + <> + {label} +
+ +
+ )} ) diff --git a/src/index.css b/src/index.css index b922105..a0cd8be 100644 --- a/src/index.css +++ b/src/index.css @@ -130,6 +130,13 @@ body { padding-inline: 0 !important; } +.listItem:hover { + .listItem-delete { + transition: opacity .25s ease-out; + opacity: 100%; + } +} + @layer base { * { @apply border-border outline-ring/50;