From df3bb661cbc96031d76cf663a589da42fbdce377 Mon Sep 17 00:00:00 2001 From: Devesh S Date: Wed, 22 Jul 2026 13:27:50 +0530 Subject: [PATCH] fix: resolve NaN and missing answers count in frontend UI --- src/pages/Community/Community.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pages/Community/Community.tsx b/src/pages/Community/Community.tsx index 702e645..cb9d9a2 100644 --- a/src/pages/Community/Community.tsx +++ b/src/pages/Community/Community.tsx @@ -75,6 +75,17 @@ export default function Community() { fetchQuestions(); }, []); + const getAnswersCount = (q: any) => { + if (Array.isArray(q.answers)) return q.answers.length; + if (typeof q.answers === 'number') return q.answers; + return 0; + }; + + const getVotesCount = (q: any) => { + const votesVal = typeof q.upvotes === 'number' ? q.upvotes : (typeof q.votes === 'number' ? q.votes : 0); + return votesVal; + }; + const filteredQuestions = questions.filter((q) => q.title.toLowerCase().includes(searchQuery.toLowerCase()) || (q.tags && q.tags.some((t: string) => t.toLowerCase().includes(searchQuery.toLowerCase()))) @@ -316,7 +327,7 @@ export default function Community() {
- {q.answers} answers + {getAnswersCount(q)} answers {q.isAnswered && ( ✓ Answered @@ -326,13 +337,13 @@ export default function Community() {