import React, { useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'; import { Button } from './ui/button'; import { Textarea } from './ui/textarea'; import { useApp } from '../contexts/AppContext'; import { Task } from '../types'; import { formatDistanceToNow } from 'date-fns'; import { Send } from 'lucide-react'; interface CommentDialogProps { open: boolean; onOpenChange: (open: boolean) => void; task: Task | null; } export const CommentDialog: React.FC = ({ open, onOpenChange, task }) => { const { addComment } = useApp(); const [commentText, setCommentText] = useState(''); const handlePost = () => { if (task && commentText.trim()) { addComment(task.id, commentText, 'Current User'); setCommentText(''); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handlePost(); } }; return ( Comments - {task?.title}
{task?.comments.length === 0 ? (

No comments yet. Be the first to comment!

) : ( task?.comments.map(comment => (
{comment.author} {formatDistanceToNow(new Date(comment.timestamp), { addSuffix: true })}

{comment.text}

)) )}