Skip to content

Commit 20e3dc6

Browse files
committed
adding loading state
1 parent ae537bd commit 20e3dc6

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

src/routes/blog/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,41 @@ import style from './style';
66

77
const blogs = (props) => {
88
const [data, isLoading] = usePrerenderData(props);
9+
return (
10+
<article class={style.blogcontainer}>
11+
{getBlogBody(data, isLoading)}
12+
</article>
13+
);
14+
};
15+
16+
function getBlogBody(data, isLoading) {
917
if (isLoading) {
10-
return (<h1>Loading</h1>);
18+
return (
19+
<div class={style.loadingPlaceholder}>
20+
<h1 class={`${style.blogtitle} loading`} >&nbsp;</h1>
21+
<caption class={`${style.blogsubtitle} loading`}>&nbsp;</caption>
22+
<div class={style.blogbody}>
23+
<div class={`${style.loadingBody} loading`} />
24+
<div class={`${style.loadingBody} loading`} />
25+
<div class={`${style.loadingBody} loading`} />
26+
</div>
27+
</div>
28+
);
1129
}
1230

1331
if (data && data.data) {
1432
const { details, content } = data.data;
1533
return (
16-
<article class={style.blogcontainer}>
34+
<div>
1735
<h1 class={style.blogtitle}>{details.title}</h1>
1836
{ details.subtitle && <caption class={style.blogsubtitle}>{details.subtitle}</caption> }
1937
{ details.cover && <img class={style.blogcover} src={details.cover} /> }
2038
<div class={style.blogbody}>
2139
<Markdown>{ content }</Markdown>
2240
</div>
23-
</article>
41+
</div>
2442
);
2543
}
26-
27-
return (<h1>Blog</h1>);
28-
};
44+
}
2945

3046
export default blogs;

src/routes/blog/style.css

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.blogtitle {
99
font-size: 2.2rem;
1010
font-weight: 400;
11-
margin-bottom: 0;
11+
margin-bottom: 8px;
1212
}
1313

1414
.blogbody {
@@ -35,3 +35,24 @@
3535
.blogcover {
3636
width: 100%;
3737
}
38+
39+
.loadingPlaceholder .blogtitle {
40+
height: 24px;
41+
}
42+
43+
.loadingPlaceholder .blogsubtitle {
44+
height: 18px;
45+
}
46+
47+
.loadingBody {
48+
height: 12px;
49+
margin-bottom: 8px;
50+
}
51+
52+
.loadingBody:nth-child(1) {
53+
width: 90%;
54+
}
55+
56+
.loadingBody:nth-child(3) {
57+
width: 65%;
58+
}

src/style/index.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,25 @@ a {
2626
text-decoration: none;
2727
color: #333;
2828
}
29+
30+
.loading {
31+
animation-duration: 1s;
32+
animation-fill-mode: forwards;
33+
animation-iteration-count: infinite;
34+
animation-name: placeHolderShimmer;
35+
animation-timing-function: linear;
36+
background: #f6f7f9;
37+
background-image: linear-gradient(to right, #f6f7f9 0%, #e9ebee 20%, #f6f7f9 40%, #f6f7f9 100%);
38+
background-repeat: no-repeat;
39+
background-size: 800px 104px;
40+
position: relative;
41+
}
42+
43+
@keyframes placeHolderShimmer{
44+
0% {
45+
background-position: -468px 0;
46+
}
47+
100% {
48+
background-position: 468px 0;
49+
}
50+
}

0 commit comments

Comments
 (0)