Skip to content

Commit

Permalink
Show list count in the communities overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
barbarah committed Sep 26, 2023
1 parent 13bdab5 commit 40dfacd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
25 changes: 24 additions & 1 deletion apps/researcher/src/app/[locale]/communities/community-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Image from 'next/image';
import {Suspense} from 'react';
import {revalidatePath} from 'next/cache';
import {ClerkAPIResponseError} from '@clerk/shared';
import {objectList} from '@colonial-collections/database';

interface MembershipCountProps {
communityId: string;
Expand All @@ -32,6 +33,26 @@ async function MembershipCount({communityId, locale}: MembershipCountProps) {
});
}

interface MembershipCountProps {
communityId: string;
locale: string;
}

async function ObjectListCount({communityId, locale}: MembershipCountProps) {
const t = await getTranslator(locale, 'Communities');

let objectLists = [];
try {
objectLists = await objectList.getListsByCommunityId(communityId);
} catch (err) {
// Don't error on the overview page. Catch this error on the detail page.
}

return t.rich('objectListCount', {
count: objectLists.length,
});
}

interface CommunityCardProps {
community: Community;
locale: string;
Expand Down Expand Up @@ -77,7 +98,9 @@ export default function CommunityCard({community, locale}: CommunityCardProps) {
<MembershipCount communityId={community.id} locale={locale} />
</Suspense>
</div>
<div className="w-1/2 p-4">{/* TODO add number of lists here */}</div>
<div className="w-1/2 p-4">
<ObjectListCount communityId={community.id} locale={locale} />
</div>
</div>
</Link>
);
Expand Down
1 change: 1 addition & 0 deletions apps/researcher/src/messages/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"error": "Something went wrong while fetching communities. Please try again later.",
"communityName": "Community of <name></name>",
"membershipCount": "{count, plural, =0 {0 members} =1 {1 member} other {# members}}",
"objectListCount": "{count, plural, =0 {0 lists} =1 {1 list} other {# lists}}",
"searchPlaceholder": "Search for community"
},
"Community": {
Expand Down
1 change: 1 addition & 0 deletions apps/researcher/src/messages/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"error": "Er is een fout opgetreden bij het ophalen van de communities. Probeer het later opnieuw.",
"communityName": "Community van <name></name>",
"membershipCount": "{count, plural, =0 {0 leden} =1 {1 lid} other {# leden}}",
"objectListCount": "{count, plural, =0 {0 lijsten} =1 {1 lijst} other {# lijsten}}",
"searchPlaceholder": "Zoek naar community"
},
"Community": {
Expand Down

0 comments on commit 40dfacd

Please sign in to comment.