Skip to content

Commit 0791194

Browse files
committed
show placeholders while loading cards data
1 parent 2572c93 commit 0791194

3 files changed

Lines changed: 89 additions & 13 deletions

File tree

src/components/ListComponent.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { useState, useEffect } from "react";
2-
import BeatLoader from "react-spinners/BeatLoader";
1+
import React, { useState, useEffect } from 'react'
32
import CarbonAd from './CarbonAd'
43
import { trackException } from '../utils/Analytics'
4+
import Placeholder from './Placeholder'
55

66
function ListComponent({ fetchData, refresh, renderItem, withAds }) {
77
const [items, setItems] = useState([])
@@ -43,17 +43,17 @@ function ListComponent({ fetchData, refresh, renderItem, withAds }) {
4343
})
4444
}
4545

46-
return (
47-
<>
48-
{loading ? (
49-
<div className="cardLoading">
50-
<BeatLoader color={'#A9B2BD'} loading={loading} size={15} className="loading" />
51-
</div>
52-
) : (
53-
renderItems()
54-
)}
55-
</>
56-
)
46+
function CustomPlaceholder() {
47+
return (
48+
<>
49+
{[...Array(5)].map((x, i) => (
50+
<Placeholder key={i} />
51+
))}
52+
</>
53+
)
54+
}
55+
56+
return <>{loading ? <CustomPlaceholder /> : renderItems()}</>
5757
}
5858

5959
export default ListComponent

src/components/Placeholder.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react'
2+
3+
function Placeholder() {
4+
return (
5+
<div
6+
style={{
7+
padding: '16px 16px 24px 16px',
8+
animation: 'react-placeholder-pulse 1.5s infinite',
9+
}}>
10+
<span
11+
style={{
12+
background: 'var(--placeholder-background-color)',
13+
display: 'block',
14+
height: '17px',
15+
}}></span>
16+
<span
17+
style={{
18+
marginTop: '8px',
19+
background: 'var(--placeholder-background-color)',
20+
display: 'block',
21+
height: '14px',
22+
width: '90%',
23+
}}
24+
/>
25+
<div
26+
style={{
27+
display: 'flex',
28+
flexDirection: 'row',
29+
marginTop: '10px',
30+
}}>
31+
<span
32+
style={{
33+
background: 'var(--placeholder-background-color)',
34+
height: '10px',
35+
width: '73px',
36+
marginRight: '16px',
37+
}}
38+
/>
39+
<span
40+
style={{
41+
background: 'var(--placeholder-background-color)',
42+
height: '10px',
43+
width: '78px',
44+
marginRight: '16px',
45+
}}
46+
/>
47+
<span
48+
style={{
49+
background: 'var(--placeholder-background-color)',
50+
height: '10px',
51+
width: '78px',
52+
}}
53+
/>
54+
</div>
55+
</div>
56+
)
57+
}
58+
59+
export default Placeholder

src/variables.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ html.dark {
4545
--tooltip-text-color: #FFF;
4646
--tooltip-shadow-color: #000000;
4747
--tooltip-accent-color: #0366D6;
48+
49+
--placeholder-background-color: #1c2026;
50+
}
51+
52+
@keyframes react-placeholder-pulse {
53+
0% {
54+
opacity: .6;
55+
}
56+
50% {
57+
opacity: 1;
58+
}
59+
100% {
60+
opacity: .6;
61+
}
4862
}
4963

5064
html.light {
@@ -93,4 +107,7 @@ html.light {
93107
--tooltip-text-color: #3C5065;
94108
--tooltip-shadow-color: #dee4ec;
95109
--tooltip-accent-color: #0366D6;
110+
111+
--placeholder-background-color: #e7eff7;
112+
96113
}

0 commit comments

Comments
 (0)