From 9829a093ca7113de4be3dc6b22519a25c5d22002 Mon Sep 17 00:00:00 2001 From: Matias Date: Tue, 22 Oct 2024 14:34:39 -0300 Subject: [PATCH] addt garden card by members when comm length is equal --- apps/web/app/(app)/gardens/page.tsx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/web/app/(app)/gardens/page.tsx b/apps/web/app/(app)/gardens/page.tsx index 4efcfeea..3df5771b 100644 --- a/apps/web/app/(app)/gardens/page.tsx +++ b/apps/web/app/(app)/gardens/page.tsx @@ -47,10 +47,26 @@ export default function Page() { return ( <> {tokenGardens - .sort( - (a, b) => - (b.communities?.length ?? 0) - (a.communities?.length ?? 0), - ) + .sort((a, b) => { + const communitiesDiff = + (b.communities?.length ?? 0) - (a.communities?.length ?? 0); + + if (communitiesDiff === 0) { + const aTotalMembers = + a.communities?.reduce( + (sum, community) => sum + (community.members?.length ?? 0), + 0, + ) ?? 0; + const bTotalMembers = + b.communities?.reduce( + (sum, community) => sum + (community.members?.length ?? 0), + 0, + ) ?? 0; + return bTotalMembers - aTotalMembers; + } + + return communitiesDiff; + }) .map((garden) => (