diff --git a/src/pages/Community/Community.tsx b/src/pages/Community/Community.tsx index 7079c62..0fe10fe 100644 --- a/src/pages/Community/Community.tsx +++ b/src/pages/Community/Community.tsx @@ -25,7 +25,7 @@ const getAvatar = (author: string) => { const getRelativeTime = (dateString: string) => { if (!dateString) return 'just now'; - + // Normalize microsecond timestamps (e.g. 2026-07-22T13:28:18.174367) to standard millisecond precision let normalized = dateString; const dotIndex = dateString.indexOf('.'); @@ -193,7 +193,7 @@ export default function Community() { }); // Optimistically update count (+1 if liked, -1 if unliked) - setQuestions((prev) => + setQuestions((prev) => prev.map((q) => { if (q.id.toString() === id) { const votesVal = typeof q.upvotes === 'number' ? q.upvotes : (typeof q.votes === 'number' ? q.votes : 0); @@ -231,11 +231,11 @@ export default function Community() { const handlePostQuestion = async () => { if (!questionText.trim()) return; - + const displayAuthor = authorName.trim() || 'Anonymous'; - + // Auto-detect hashtags based on question text content - const detectedTags = TRENDING_TAGS.filter(tag => + const detectedTags = TRENDING_TAGS.filter(tag => questionText.toLowerCase().includes(tag.toLowerCase()) ); const finalTags = detectedTags.length > 0 ? detectedTags : ['fresher', 'general']; @@ -401,11 +401,10 @@ export default function Community() { - - {/* Upvotes button */} - - - {/* Tags Inline */} -
- {(q.tags || []).map((tag) => ( - { e.stopPropagation(); setSearchQuery(tag); }} - className="px-1.5 py-0.5 rounded bg-slate-50 text-[10px] font-semibold text-slate-400 border border-slate-100 hover:bg-slate-100 hover:text-slate-600 transition-colors" - style={{ fontFamily: 'Inter, sans-serif' }} - > - #{tag} - - ))} -
- - - - {/* Expandable Answers Section */} - {expandedQuestionIds.has(q.id.toString()) && ( -
e.stopPropagation()}> -
-

- Replies ({ansCount}) -

-
- {Array.isArray(q.answers) && q.answers.length > 0 ? ( -
- {q.answers.map((ans: any) => ( -
- {/* Thread connector line */} -
- - {/* Senior Avatar */} - {ans.author} - -
-
- {ans.author} - {/* Blue verified check icon for senior helpers */} - - - - - - - {getRelativeTime(ans.createdAt)} -
-

- {ans.body} -

-
-
- ))} + {/* Badges on Top Right */} +
+ {isTrending && ( + ★ Trending + )} + {q.isAnswered || ansCount > 0 ? ( + ✓ Answered + ) : ( + Unanswered + )} +
+
+ +

+ {q.title} +

+ +

+ {q.body} +

+ +
+ {/* Left side: Replies & Likes & Tags inline */} +
+ {/* Replies button */} + + + {/* Upvotes button */} + + + {/* Tags Inline */} +
+ {(q.tags || []).map((tag) => ( + { e.stopPropagation(); setSearchQuery(tag); }} + className="px-1.5 py-0.5 rounded bg-slate-50 text-[10px] font-semibold text-slate-400 border border-slate-100 hover:bg-slate-100 hover:text-slate-600 transition-colors" + style={{ fontFamily: 'Inter, sans-serif' }} + > + #{tag} + + ))} +
+
+
+ + {/* Expandable Answers Section */} + {expandedQuestionIds.has(q.id.toString()) && ( +
e.stopPropagation()}> +
+

+ Replies ({ansCount}) +

+
+ {Array.isArray(q.answers) && q.answers.length > 0 ? ( +
+ {q.answers.map((ans: any) => ( +
+ {/* Thread connector line */} +
+ + {/* Senior Avatar */} + {ans.author} + +
+
+ {ans.author} + {/* Blue verified check icon for senior helpers */} + + + + + + + {getRelativeTime(ans.createdAt)} +
+

+ {ans.body} +

+
+
+ ))} +
+ ) : ( +

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

+ )}
- ) : ( -

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

)}
- )} -
-
- - - ); - })} - - )} + + + + ); + })} + + )} - {/* Pagination — arrows only */} - {!loading && totalPages > 1 && ( -
- handlePageChange(currentPage - 1)} - disabled={currentPage === 0 || loading} - className={`flex items-center gap-1.5 px-4 py-2 rounded-xl border text-[12px] font-semibold transition-all duration-200 ${ - currentPage === 0 - ? 'border-slate-100 bg-slate-50 text-slate-300 cursor-not-allowed' - : 'border-slate-200 bg-white text-slate-700 hover:bg-slate-50 hover:border-slate-300 shadow-sm cursor-pointer' - }`} - style={{ fontFamily: 'Poppins, sans-serif' }} - > - - Prev - + {/* Pagination — arrows only */} + {!loading && totalPages > 1 && ( +
+ handlePageChange(currentPage - 1)} + disabled={currentPage === 0 || loading} + className={`flex items-center gap-1.5 px-4 py-2 rounded-xl border text-[12px] font-semibold transition-all duration-200 ${currentPage === 0 + ? 'border-slate-100 bg-slate-50 text-slate-300 cursor-not-allowed' + : 'border-slate-200 bg-white text-slate-700 hover:bg-slate-50 hover:border-slate-300 shadow-sm cursor-pointer' + }`} + style={{ fontFamily: 'Poppins, sans-serif' }} + > + + Prev + - - Page {currentPage + 1} of {totalPages} · {filteredQuestions.length} questions - + + Page {currentPage + 1} of {totalPages} · {filteredQuestions.length} questions + - handlePageChange(currentPage + 1)} - disabled={currentPage >= totalPages - 1 || loading} - className={`flex items-center gap-1.5 px-4 py-2 rounded-xl border text-[12px] font-semibold transition-all duration-200 ${ - currentPage >= totalPages - 1 - ? 'border-slate-100 bg-slate-50 text-slate-300 cursor-not-allowed' - : 'border-slate-200 bg-white text-slate-700 hover:bg-slate-50 hover:border-slate-300 shadow-sm cursor-pointer' - }`} - style={{ fontFamily: 'Poppins, sans-serif' }} - > - Next - - -
- )} + handlePageChange(currentPage + 1)} + disabled={currentPage >= totalPages - 1 || loading} + className={`flex items-center gap-1.5 px-4 py-2 rounded-xl border text-[12px] font-semibold transition-all duration-200 ${currentPage >= totalPages - 1 + ? 'border-slate-100 bg-slate-50 text-slate-300 cursor-not-allowed' + : 'border-slate-200 bg-white text-slate-700 hover:bg-slate-50 hover:border-slate-300 shadow-sm cursor-pointer' + }`} + style={{ fontFamily: 'Poppins, sans-serif' }} + > + Next + + +
+ )} @@ -803,11 +796,10 @@ export default function Community() {