Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Commit 225f861

Browse files
committed
Feat: Add animations to volunteer page
1 parent 9dff610 commit 225f861

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/components/Volunteers.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Footer from './Footer';
33
// import {API_DOMAIN} from '../constants';
44
import {fetcher} from '../utils/commonFunctions';
55

6+
import {useTransition, animated} from '@react-spring/web';
67
import classnames from 'classnames';
78
import {useMemo, useEffect} from 'react';
89
import {
@@ -15,12 +16,11 @@ import {
1516
import {Helmet} from 'react-helmet';
1617
import useSWR from 'swr';
1718

18-
const VOLUNTEERS_DOMAIN =
19-
'https://raw.githubusercontent.com/shuklaayush/testing/gh-pages';
20-
const PLACEHOLDER_IMG =
21-
'https://images.assetsdelivery.com/compings_v2/apoev/apoev1901/apoev190100061.jpg';
19+
const VOLUNTEERS_DOMAIN = 'https://volunteers.covid19india.org';
20+
// 'https://raw.githubusercontent.com/shuklaayush/testing/gh-pages';
21+
const PLACEHOLDER_IMG = 'placeholder.jpg';
2222

23-
function Member({className, name, bio, link, image, socials = {}}) {
23+
function Member({className, style, name, bio, link, image, socials = {}}) {
2424
const socialIcons = useMemo(
2525
() => ({
2626
github: <GitHub size={16} />,
@@ -32,10 +32,10 @@ function Member({className, name, bio, link, image, socials = {}}) {
3232
);
3333

3434
return (
35-
<div className={classnames('Member', className)}>
35+
<animated.div className={classnames('Member', className)} {...{style}}>
3636
{link && <a href={link} target="_blank" rel="noopener noreferrer"></a>}
3737
<img
38-
src={image ? `${VOLUNTEERS_DOMAIN}/images/${image}` : PLACEHOLDER_IMG}
38+
src={`${VOLUNTEERS_DOMAIN}/images/${image ? image : PLACEHOLDER_IMG}`}
3939
/>
4040
<div className="details">
4141
<h2 className="name">{name}</h2>
@@ -62,16 +62,26 @@ function Member({className, name, bio, link, image, socials = {}}) {
6262
<ExternalLink size={16} />
6363
</div>
6464
)}
65-
</div>
65+
</animated.div>
6666
);
6767
}
6868

69-
// TODO: Animations, lazy-loading and content loader
69+
// TODO: Lazy-loading and content loader
7070
function Volunteers() {
7171
const {data} = useSWR(`${VOLUNTEERS_DOMAIN}/data.json`, fetcher, {
7272
suspense: true,
7373
});
7474

75+
const dataAugemented = useMemo(() => [...(data || []), {}], [data]);
76+
77+
const transition = useTransition(dataAugemented, {
78+
delay: 200,
79+
trail: 200 / dataAugemented.length,
80+
from: {opacity: 0, scale: 0.8},
81+
enter: {opacity: 1, scale: 1},
82+
leave: {opacity: 0, scale: 0},
83+
});
84+
7585
useEffect(() => {
7686
window.scrollTo(0, 0);
7787
}, []);
@@ -88,21 +98,27 @@ function Volunteers() {
8898

8999
<div className="Volunteers">
90100
<div className="wrapper">
91-
<div className="description">
101+
<div
102+
className={classnames('description', 'fadeInUp')}
103+
style={{animationDelay: '0.1s'}}
104+
>
92105
PLACEHOLDER: We would like to thank the hundreds of volunteers who,
93106
for the last 18 months, collected and published the most complete
94107
data about COVID-19 in India.
95108
</div>
96109
</div>
97110
<div className="members">
98-
{data.map((member, index) => (
99-
<Member key={index} {...member} />
100-
))}
101-
<div className="last">
102-
<Member className={'first'} />
103-
<Member className={'second'} />
104-
<Member className={'third'} bio="And many more..." />
105-
</div>
111+
{transition((style, item) =>
112+
Object.keys(item || {}).length > 0 ? (
113+
<Member {...item} {...{style}} />
114+
) : (
115+
<animated.div className="last" {...{style}}>
116+
<Member className={'first'} />
117+
<Member className={'second'} />
118+
<Member className={'third'} bio="And many more..." />
119+
</animated.div>
120+
)
121+
)}
106122
</div>
107123
</div>
108124
<Footer />

0 commit comments

Comments
 (0)