From 132f3edbd4afd417ea51f2beb2d4ee973a0df3ff Mon Sep 17 00:00:00 2001 From: Devesh S Date: Wed, 22 Jul 2026 14:08:48 +0530 Subject: [PATCH] feat: add option to display answers for the questions --- src/pages/Community/Community.tsx | 59 ++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/pages/Community/Community.tsx b/src/pages/Community/Community.tsx index 916dc40..9101410 100644 --- a/src/pages/Community/Community.tsx +++ b/src/pages/Community/Community.tsx @@ -71,8 +71,21 @@ export default function Community() { const [confessionPosted, setConfessionPosted] = useState(false); const [searchQuery, setSearchQuery] = useState(''); const [likedIds, setLikedIds] = useState>(new Set()); + const [expandedQuestionIds, setExpandedQuestionIds] = useState>(new Set()); const [questions, setQuestions] = useState(QUESTIONS_DATA); + const toggleAnswers = (id: string) => { + setExpandedQuestionIds((prev) => { + const next = new Set(prev); + if (next.has(id.toString())) { + next.delete(id.toString()); + } else { + next.add(id.toString()); + } + return next; + }); + }; + const fetchQuestions = async () => { try { const response = await fetch('http://localhost:8080/api/questions'); @@ -352,10 +365,17 @@ export default function Community() {
- - - {getAnswersCount(q)} answers - + {q.isAnswered && ( ✓ Answered )} @@ -374,6 +394,37 @@ export default function Community() {
+ + {/* Expandable Answers Section */} + {expandedQuestionIds.has(q.id.toString()) && ( +
+
+

+ Answers ({getAnswersCount(q)}) +

+
+ {Array.isArray(q.answers) && q.answers.length > 0 ? ( +
+ {q.answers.map((ans: any) => ( +
+
+ {ans.author} + + {getRelativeTime(ans.createdAt)} +
+

+ {ans.body} +

+
+ ))} +
+ ) : ( +

+ No answers posted yet. Senior helpers can reply to this question via the Telegram Bot! +

+ )} +
+ )}