diff --git a/src/components/forum/ThreadDetail.tsx b/src/components/forum/ThreadDetail.tsx index e5703a0f..9ba02ab9 100644 --- a/src/components/forum/ThreadDetail.tsx +++ b/src/components/forum/ThreadDetail.tsx @@ -31,6 +31,7 @@ export const ThreadDetail: React.FC = ({ courseId, threadId, ) + const queryClient = useQueryClient() const [replyContent, setReplyContent] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) @@ -42,12 +43,15 @@ export const ThreadDetail: React.FC = ({ try { setIsSubmitting(true) await replyToThread(courseId, threadId, replyContent) + await queryClient.invalidateQueries({ queryKey: ["forum", "thread", courseId, threadId], }) + await queryClient.invalidateQueries({ queryKey: ["forum", "threads", courseId], }) + setReplyContent("") } catch (err) { console.error("Failed to post reply", err) @@ -58,11 +62,14 @@ export const ThreadDetail: React.FC = ({ const handleDeleteThread = async () => { if (!confirm("Are you sure you want to delete this thread?")) return + try { await deleteThread(courseId, threadId) + await queryClient.invalidateQueries({ queryKey: ["forum", "threads", courseId], }) + onBack() } catch (err) { console.error("Failed to delete thread", err) @@ -71,8 +78,10 @@ export const ThreadDetail: React.FC = ({ const handleDeleteReply = async (replyId: number) => { if (!confirm("Are you sure you want to delete this reply?")) return + try { await deleteReply(courseId, replyId) + await queryClient.invalidateQueries({ queryKey: ["forum", "thread", courseId, threadId], }) @@ -82,7 +91,11 @@ export const ThreadDetail: React.FC = ({ } if (isLoading) { - return
Loading discussion...
+ return ( +
+ Loading discussion... +
+ ) } if (error || !thread) { @@ -91,6 +104,7 @@ export const ThreadDetail: React.FC = ({ +
Thread not found or failed to load.
@@ -110,7 +124,9 @@ export const ThreadDetail: React.FC = ({
-

{thread.title}

+

+ {thread.title} +

{(isAdmin || currentAddress === thread.author_address) && (
- {reply.content} + + {reply.content} +
))} @@ -200,7 +230,9 @@ export const ThreadDetail: React.FC = ({