import { useState } from 'react'; import { MessageCircle, ThumbsUp, Send, Clock } from 'lucide-react'; export default function DiscussionApp() { const [posts, setPosts] = useState([]); const [newPost, setNewPost] = useState(''); const addPost = (e) => { e.preventDefault(); if (!newPost.trim()) return; const post = { id: Date.now(), content: newPost, likes: 0, timestamp: new Date(), replies: [], author: 'User' }; setPosts([post, ...posts]); setNewPost(''); }; const addReply = (postId, replyContent) => { setPosts(posts.map(post => { if (post.id === postId) { return { ...post, replies: [...post.replies, { id: Date.now(), content: replyContent, timestamp: new Date(), author: 'User' }] }; } return post; })); }; const handleLike = (postId) => { setPosts(posts.map(post => post.id === postId ? { ...post, likes: post.likes + 1 } : post )); }; const formatTime = (date) => { return new Date(date).toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric' }); }; return (

Discussion Board

{/* Post Creation Form */}
setNewPost(e.target.value)} placeholder="What's on your mind?" className="flex-1 p-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
{/* Posts List */}
{posts.map(post => (
{post.author[0]}

{post.author}

{formatTime(post.timestamp)}

{post.content}

{/* Replies */} {post.replies.length > 0 && (
{post.replies.map(reply => (
{reply.author[0]}

{reply.author}

{formatTime(reply.timestamp)}

{reply.content}

))}
)}
))}
); } function ReplyForm({ postId, onReply }) { const [isReplying, setIsReplying] = useState(false); const [replyContent, setReplyContent] = useState(''); const handleSubmit = (e) => { e.preventDefault(); if (!replyContent.trim()) return; onReply(postId, replyContent); setReplyContent(''); setIsReplying(false); }; return (
{isReplying && (
setReplyContent(e.target.value)} placeholder="Write a reply..." className="w-full p-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
)}
); }