From 7ec6506d727e8605949b162b7043bdd6ff0c21a6 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Sat, 7 Feb 2026 15:27:42 +0530 Subject: [PATCH] feat(comments): update comment sorting to display latest comments first --- frontend/src/app/boards/[boardId]/page.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/boards/[boardId]/page.tsx b/frontend/src/app/boards/[boardId]/page.tsx index 9fd5b2d2..0778e73e 100644 --- a/frontend/src/app/boards/[boardId]/page.tsx +++ b/frontend/src/app/boards/[boardId]/page.tsx @@ -1135,18 +1135,23 @@ export default function BoardDetailPage() { payload.comment?.created_at, ); if (prev.length === 0 || createdMs === null) { - return [...prev, payload.comment as TaskComment]; + return [payload.comment as TaskComment, ...prev]; + } + const first = prev[0]; + const firstMs = apiDatetimeToMs(first?.created_at); + if (firstMs !== null && createdMs >= firstMs) { + return [payload.comment as TaskComment, ...prev]; } const last = prev[prev.length - 1]; const lastMs = apiDatetimeToMs(last?.created_at); - if (lastMs !== null && createdMs >= lastMs) { + if (lastMs !== null && createdMs <= lastMs) { return [...prev, payload.comment as TaskComment]; } const next = [...prev, payload.comment as TaskComment]; next.sort((a, b) => { const aTime = apiDatetimeToMs(a.created_at) ?? 0; const bTime = apiDatetimeToMs(b.created_at) ?? 0; - return aTime - bTime; + return bTime - aTime; }); return next; }); @@ -1607,7 +1612,7 @@ export default function BoardDetailPage() { items.sort((a, b) => { const aTime = apiDatetimeToMs(a.created_at) ?? 0; const bTime = apiDatetimeToMs(b.created_at) ?? 0; - return aTime - bTime; + return bTime - aTime; }); setComments(items); } catch (err) {