-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
77 lines (66 loc) · 2.45 KB
/
index.tsx
File metadata and controls
77 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use client';
import { useEffect, useRef, useState } from 'react';
import type { FC } from 'react';
import { LOGO_PARTNERS } from '#site/next.partners.constants';
import type { PartnerCategory, Partners } from '#site/types';
import PartnerLogo from '../PartnerLogo';
import style from './index.module.css';
import { randomPartnerList } from '../utils';
type PartnersLogoListProps = {
maxLength?: number;
categories?: PartnerCategory;
sort?: 'name' | 'weight';
};
const PartnersLogoList: FC<PartnersLogoListProps> = ({
maxLength = 3,
sort = 'weight',
categories,
}) => {
const initialRenderer = useRef(true);
const [seedList, setSeedList] = useState<Array<Partners>>(() => {
if (maxLength === null) {
return LOGO_PARTNERS.filter(
partner => !categories || partner.categories.includes(categories)
);
}
return LOGO_PARTNERS.slice(0, maxLength);
});
useEffect(() => {
// We intentionally render the initial default "mock" list of sponsors
// to have the Skeletons loading, and then we render the actual list
// after an enough amount of time has passed to give a proper sense of Animation
// We do this client-side effect, to ensure that a random-amount of sponsors is renderered
// on every page load. Since our page is natively static, we need to ensure that
// on the client-side we have a random amount of sponsors rendered.
// Although whilst we are deployed on Vercel or other environment that supports ISR
// (Incremental Static Generation) whose would invalidate the cache every 5 minutes
// We want to ensure that this feature is compatible on a full-static environment
const renderSponsorsAnimation = setTimeout(() => {
initialRenderer.current = false;
setSeedList(
randomPartnerList(LOGO_PARTNERS, {
pick: maxLength,
dateSeed: 5,
category: categories,
sort,
})
);
}, 0);
return () => clearTimeout(renderSponsorsAnimation);
// We only want this to run once on initial render
// We don't really care if the props change as realistically they shouldn't ever
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<div className={style.partnersLogoList}>
{seedList.map((partner, index) => (
<PartnerLogo
{...partner}
key={index}
loading={initialRenderer.current}
/>
))}
</div>
);
};
export default PartnersLogoList;