/** * 论坛帖子详情组件 - GitHub Discussions * Forum post detail component - GitHub Discussions */ import { useState } from 'react'; import { ArrowLeft, ThumbsUp, MessageCircle, Clock, Send, RefreshCw, CornerDownRight, ExternalLink, CheckCircle } from 'lucide-react'; import { open } from '@tauri-apps/plugin-shell'; import { useLocale } from '../../hooks/useLocale'; import { usePost, useReplies } from '../../hooks/useForum'; import { getForumService } from '../../services/forum'; import type { Reply } from '../../services/forum'; import { parseEmoji } from './utils'; import './ForumPostDetail.css'; interface ForumPostDetailProps { postNumber: number; currentUserId: string; onBack: () => void; } export function ForumPostDetail({ postNumber, currentUserId, onBack }: ForumPostDetailProps) { const { t } = useLocale(); const { post, loading: postLoading, toggleUpvote, refetch: refetchPost } = usePost(postNumber); const { replies, loading: repliesLoading, createReply, refetch: refetchReplies } = useReplies(postNumber); const [replyContent, setReplyContent] = useState(''); const [replyingTo, setReplyingTo] = useState(null); const [submitting, setSubmitting] = useState(false); const forumService = getForumService(); const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleString(); }; const handleSubmitReply = async (e: React.FormEvent) => { e.preventDefault(); if (!replyContent.trim() || submitting || !post) return; setSubmitting(true); try { await createReply(post.id, replyContent, replyingTo || undefined); setReplyContent(''); setReplyingTo(null); refetchPost(); } finally { setSubmitting(false); } }; const handleToggleReplyUpvote = async (replyId: string, hasUpvoted: boolean) => { await forumService.toggleReplyUpvote(replyId, hasUpvoted); refetchReplies(); }; const openInGitHub = async (url: string) => { await open(url); }; const renderReply = (reply: Reply, depth: number = 0) => { return (
{reply.author.login} @{reply.author.login} {reply.isAnswer && ( {t('forum.answer')} )}
{formatDate(reply.createdAt)}
{replyingTo === reply.id && post && (