Skip to content

Commit 95c9a3e

Browse files
committed
refactor the placeholders
1 parent 0791194 commit 95c9a3e

6 files changed

Lines changed: 99 additions & 66 deletions

File tree

src/App.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,72 @@ Producthunt item
876876
}
877877
}
878878

879+
@keyframes cardPlaceholderPulse {
880+
0% {
881+
opacity: .6;
882+
}
883+
50% {
884+
opacity: 1;
885+
}
886+
100% {
887+
opacity: .6;
888+
}
889+
}
890+
891+
.cardPlaceholder {
892+
padding: 16px 16px 24px 16px;
893+
animation-duration: 1.5s;
894+
animation-name: cardPlaceholderPulse;
895+
animation-iteration-count: infinite;
896+
}
897+
.mediaCardPlaceholder {
898+
display: flex;
899+
flex-direction: row;
900+
}
901+
902+
.cardPlaceholder .media {
903+
width: 50px;
904+
height: 50px;
905+
margin-right: 16px;
906+
background: var(--placeholder-background-color);
907+
display: inline-block;
908+
}
909+
.cardPlaceholder .cardContent {
910+
display: flex;
911+
flex-direction: column;
912+
}
913+
.cardPlaceholder .cardUpvote {
914+
margin-left: auto;
915+
background: var(--placeholder-background-color);
916+
width: 33px;
917+
height: 44px;
918+
}
919+
.cardPlaceholder .line {
920+
background: var(--placeholder-background-color);
921+
display: block;
922+
height: 17px;
923+
border-radius: 4px;
924+
}
925+
.cardPlaceholder .smallLine {
926+
margin-top: 8px;
927+
background: var(--placeholder-background-color);
928+
display: block;
929+
height: 14px;
930+
width: 90%;
931+
border-radius: 4px;
932+
}
933+
.cardPlaceholder .details {
934+
display: flex;
935+
flex-direction: row;
936+
margin-top: 10px;
937+
}
938+
.cardPlaceholder .detail {
939+
background: var(--placeholder-background-color);
940+
height: 10px;
941+
width: 73px;
942+
margin-right: 16px;
943+
border-radius: 4px;
944+
}
879945
/* Small devices (portrait tablets and large phones, 600px and up) */
880946
@media only screen and (min-width: 600px) {
881947
.block {

src/cards/ProductHuntCard.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import React, { useEffect, useState, useContext } from 'react'
3-
import { SiProducthunt } from 'react-icons/si';
43
import CardComponent from "../components/CardComponent";
54
import ListComponent from "../components/ListComponent";
65
import { BiCommentDetail } from "react-icons/bi"
@@ -9,6 +8,7 @@ import PreferencesContext from '../preferences/PreferencesContext'
98
import CardLink from "../components/CardLink"
109
import CardItemWithActions from '../components/CardItemWithActions'
1110
import producthuntApi from '../services/producthunt'
11+
import ProductHuntPlaceholder from '../components/ProductHuntPlaceholder'
1212

1313
const ProductItem = ({ item, index, analyticsTag }) => {
1414

@@ -78,6 +78,7 @@ function ProductHuntCard({ label, icon, analyticsTag, withAds }) {
7878
<ListComponent
7979
fetchData={fetchProducts}
8080
renderItem={renderItem}
81+
placeholder={<ProductHuntPlaceholder />}
8182
refresh={refresh}
8283
withAds={withAds}
8384
/>

src/components/ListComponent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CarbonAd from './CarbonAd'
33
import { trackException } from '../utils/Analytics'
44
import Placeholder from './Placeholder'
55

6-
function ListComponent({ fetchData, refresh, renderItem, withAds }) {
6+
function ListComponent({ fetchData, refresh, renderItem, withAds, placeholder = <Placeholder /> }) {
77
const [items, setItems] = useState([])
88
const [loading, setLoading] = useState(true)
99
const [error, setError] = useState(null)
@@ -43,17 +43,17 @@ function ListComponent({ fetchData, refresh, renderItem, withAds }) {
4343
})
4444
}
4545

46-
function CustomPlaceholder() {
46+
function Placeholders() {
4747
return (
4848
<>
4949
{[...Array(5)].map((x, i) => (
50-
<Placeholder key={i} />
50+
<span key={i}>{placeholder}</span>
5151
))}
5252
</>
5353
)
5454
}
5555

56-
return <>{loading ? <CustomPlaceholder /> : renderItems()}</>
56+
return <>{loading ? <Placeholders /> : renderItems()}</>
5757
}
5858

5959
export default ListComponent

src/components/Placeholder.js

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,13 @@ import React from 'react'
22

33
function Placeholder() {
44
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-
/>
5+
<div className="cardPlaceholder">
6+
<span className="line"></span>
7+
<span className="smallLine" />
8+
<div className="details">
9+
<span className="detail" />
10+
<span className="detail" style={{ width: '78px' }} />
11+
<span className="detail" style={{ width: '78px' }} />
5412
</div>
5513
</div>
5614
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
3+
function ProductHuntPlaceholder() {
4+
return (
5+
<div className="cardPlaceholder mediaCardPlaceholder">
6+
<span className="media" />
7+
<div className="cardContent">
8+
<span className="line" />
9+
<span className="smallLine" />
10+
<div className="details">
11+
<span className="detail" />
12+
<span className="detail" style={{ width: '120px' }} />
13+
</div>
14+
</div>
15+
<div className="cardUpvote" />
16+
</div>
17+
)
18+
}
19+
20+
export default ProductHuntPlaceholder

src/variables.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ html.dark {
4949
--placeholder-background-color: #1c2026;
5050
}
5151

52-
@keyframes react-placeholder-pulse {
53-
0% {
54-
opacity: .6;
55-
}
56-
50% {
57-
opacity: 1;
58-
}
59-
100% {
60-
opacity: .6;
61-
}
62-
}
63-
6452
html.light {
6553
--app-name-text-color: #253B53;
6654
--background-color: #EFF6FE;

0 commit comments

Comments
 (0)