Skip to content

Commit 19d1d36

Browse files
authored
apply suggestions
1 parent bc52348 commit 19d1d36

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Tooltip from '@node-core/ui-components/Common/Tooltip';
44
import * as PartnerLogos from '@node-core/ui-components/Icons/PartnerLogos';
55

6-
import { providePartners } from '#site/next-data/providers/partners';
6+
import providePartners from '#site/next-data/providers/partners';
77
import { partners } from '#site/next.json.mjs';
88

99
import type { Partner, PartnerCategory } from '#site/types';
@@ -76,8 +76,10 @@ const PartnersList: FC<PartnersListProps> = async ({
7676
}) => {
7777
const isSmall = size === 'small';
7878

79+
const SMALL_PARTNER_LIMIT = 6;
80+
7981
const partners = await getPartners(
80-
length ?? (isSmall ? 6 : undefined),
82+
length ?? (isSmall ? SMALL_PARTNER_LIMIT : undefined),
8183
category,
8284
sort
8385
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { partners } from '#site/next.json.mjs';
2+
import { shuffle } from '#site/util/array';
3+
4+
/**
5+
* Provides the weighted and shuffled partners array.
6+
* Results are cached using React's cache directive.
7+
* @param seed - The seed for deterministic shuffling
8+
* @param category - Optional category to filter partners
9+
*/
10+
const providePartners = async (seed, category) => {
11+
// Create weighted array (duplicates based on weight)
12+
const weightedPartners = partners.flatMap(partner => {
13+
const weight = partner.weight ?? 0;
14+
return Array(weight > 0 ? weight : 1).fill(partner);
15+
});
16+
17+
// Shuffle and remove duplicates
18+
const shuffled = await shuffle(weightedPartners, seed);
19+
const unique = Array.from(new Set(shuffled));
20+
21+
return category
22+
? unique.filter(p => p.categories.includes(category))
23+
: unique;
24+
};
25+
26+
export default providePartners;
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
'use cache';
22

3-
import { partners } from '#site/next.json.mjs';
4-
import { shuffle } from '#site/util/array';
3+
import providePartners from '#site/next-data/generators/partners.mjs';
54

6-
import type { Partner, PartnerCategory } from '#site/types';
7-
8-
/**
9-
* Provides the weighted and shuffled partners array.
10-
* Results are cached using React's cache directive.
11-
* @param seed - The seed for deterministic shuffling
12-
* @param category - Optional category to filter partners
13-
*/
14-
export const providePartners = async (
15-
seed: number,
16-
category?: PartnerCategory
17-
): Promise<Array<Partner>> => {
18-
// Create weighted array (duplicates based on weight)
19-
const weightedPartners = partners.flatMap(partner => {
20-
const weight = partner.weight ?? 0;
21-
return Array(weight > 0 ? weight : 1).fill(partner);
22-
});
23-
24-
// Shuffle and remove duplicates
25-
const shuffled = await shuffle(weightedPartners, seed);
26-
const unique = Array.from(new Set(shuffled));
27-
28-
return category
29-
? unique.filter(p => p.categories.includes(category))
30-
: unique;
31-
};
5+
export default providePartners;

0 commit comments

Comments
 (0)