import { useState } from 'react'; import { ArrowLeft, Send, User, Clock, ThumbsUp } from 'lucide-react'; import { ForumThread } from './ThreadCard'; import { useTelegram } from '../../hooks/useTelegram'; export interface ForumReply { id: string; content: string; author: string; authorAddress?: string; createdAt: Date; likes: number; userLiked?: boolean; } interface ThreadViewProps { thread: ForumThread; replies: ForumReply[]; onBack: () => void; onReply: (content: string) => void; onLikeReply: (replyId: string) => void; isConnected: boolean; } export function ThreadView({ thread, replies, onBack, onReply, onLikeReply, isConnected }: ThreadViewProps) { const { hapticImpact, showBackButton, hideBackButton, isTelegram } = useTelegram(); const [replyContent, setReplyContent] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); // Setup Telegram back button useState(() => { if (isTelegram) { showBackButton(onBack); return () => hideBackButton(); } }); const formatDate = (date: Date) => { return date.toLocaleDateString('tr-TR', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }); }; const handleSubmitReply = async () => { if (!replyContent.trim() || isSubmitting) return; setIsSubmitting(true); if (isTelegram) { hapticImpact('medium'); } try { await onReply(replyContent); setReplyContent(''); } finally { setIsSubmitting(false); } }; return (
{/* Header */}

{thread.title}

{/* Content */}
{/* Original post */}

{thread.author}

{formatDate(thread.createdAt)}
{/* Tags */} {thread.tags && thread.tags.length > 0 && (
{thread.tags.map(tag => ( {tag} ))}
)}

{thread.content}

{/* Replies */}

{replies.length} {replies.length === 1 ? 'Reply' : 'Replies'}

{replies.map(reply => (
{reply.author} {formatDate(reply.createdAt)}

{reply.content}

))} {replies.length === 0 && (
No replies yet. Be the first to reply!
)}
{/* Reply input */} {isConnected ? (
setReplyContent(e.target.value)} placeholder="Write a reply..." className="flex-1 bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm placeholder-gray-500 focus:outline-none focus:border-green-500" onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmitReply(); } }} />
) : (
Connect wallet to reply
)}
); }