diff --git a/app/w/[id]/components/comment-block/comment-block.tsx b/app/w/[id]/components/comment-block/comment-block.tsx new file mode 100644 index 0000000000..0b01970789 --- /dev/null +++ b/app/w/[id]/components/comment-block/comment-block.tsx @@ -0,0 +1,106 @@ +import { useState, useEffect, useRef } from 'react' +import { Card } from '@/components/ui/card' +import { Textarea } from '@/components/ui/textarea' +import { X } from 'lucide-react' +import { useCommentStore } from '@/stores/comments/store' +import { NodeProps } from 'reactflow' +import { cn } from '@/lib/utils' + +interface CommentBlockData { + id: string + text: string +} + +export function CommentBlock({ data }: NodeProps) { + const [text, setText] = useState(data.text) + const [isEditing, setIsEditing] = useState(!data.text) + const [isExpanded, setIsExpanded] = useState(false) + const textareaRef = useRef(null) + const { updateComment, removeComment } = useCommentStore() + + useEffect(() => { + if (isEditing && textareaRef.current) { + textareaRef.current.focus() + } + }, [isEditing]) + + const handleBlur = () => { + setIsEditing(false) + setIsExpanded(false) + if (text.trim()) { + updateComment(data.id, text) + } else { + removeComment(data.id) + } + } + + const handleClick = () => { + setIsExpanded(true) + if (!text) { + setIsEditing(true) + } + } + + if (!isExpanded) { + return ( +
setIsExpanded(true)} + > +
+
+ ) + } + + return ( + !isEditing && setIsExpanded(false)} + > +
+
Note
+ +
+ +
setIsEditing(true)}> + {isEditing ? ( +