Skip to content

Commit

Permalink
addt garden card by members when comm length is equal
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati0x committed Oct 22, 2024
1 parent be7e332 commit 9829a09
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions apps/web/app/(app)/gardens/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<div key={garden.id}>
<GardenCard garden={garden} />
Expand Down

0 comments on commit 9829a09

Please sign in to comment.