Skip to content

Commit 392d60e

Browse files
committed
feat: supporters provider created
1 parent 5b470d5 commit 392d60e

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

apps/site/components/Common/Supporters/index.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22

33
import Avatar from '@node-core/ui-components/Common/AvatarGroup/Avatar';
44
import type { FC } from 'react';
5-
import { use } from 'react';
65

76
import type { Supporters } from '#site/types';
87

9-
type SupportersProps = {
10-
supporters: Promise<Array<Supporters>>;
8+
type SupportersListProps = {
9+
supporters: Array<Supporters>;
1110
};
1211

1312
// TODO: Sort supporters by all time contribution amount and link to their Open Collective page
14-
const SupportersList: FC<SupportersProps> = ({ supporters }) => {
15-
const supportersList = use(supporters);
16-
17-
return (
18-
<div className="flex max-w-full flex-wrap items-center justify-center gap-1">
19-
{supportersList.map(({ name, image }, i) => (
20-
<Avatar nickname={name} image={image} key={`${name}-${i}`} />
21-
))}
22-
</div>
23-
);
24-
};
13+
const SupportersList: FC<SupportersListProps> = ({ supporters }) => (
14+
<div className="flex max-w-full flex-wrap items-center justify-center gap-1">
15+
{supporters.map(({ name, image }, i) => (
16+
<Avatar nickname={name} image={image} key={`${name}-${i}`} />
17+
))}
18+
</div>
19+
);
2520

2621
export default SupportersList;

apps/site/components/withSupporters.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
'use server';
12
import type { FC, PropsWithChildren } from 'react';
23

3-
import { fetchOpenCollectiveData } from '#site/next-data/generators/supportersData.mjs';
4-
import type { Supporters } from '#site/types';
5-
64
import SupportersList from './Common/Supporters';
75

6+
import provideSupporters from '#site/next-data/providers/supportersData';
7+
88
const WithSupporters: FC<PropsWithChildren> = () => {
9-
const supporters = fetchOpenCollectiveData() as Promise<Array<Supporters>>;
9+
const supporters = provideSupporters();
1010

1111
return (
1212
<div className="flex max-w-full flex-wrap items-center gap-1">

apps/site/next-data/generators/supportersData.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Fetches supporters data from Open Collective API, filters active backers,
3+
* and maps it to the Supporters type.
4+
*
5+
* @returns {Promise<Array<import('#site/types/supporters')>>} Array of supporters
6+
*/
17
async function fetchOpenCollectiveData() {
28
const endpoint = 'https://opencollective.com/nodejs/members/all.json';
39

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { cache } from 'react';
2+
3+
import { fetchOpenCollectiveData } from '#site/next-data/generators/supportersData.mjs';
4+
5+
const openCollectiveSupporters = await fetchOpenCollectiveData();
6+
7+
const provideSupporters = cache(() => openCollectiveSupporters);
8+
9+
export default provideSupporters;

0 commit comments

Comments
 (0)