Skip to content

Commit 4f22d33

Browse files
committed
building photograph page
1 parent 7595cbf commit 4f22d33

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

src/routes/photographs/index.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
import { h } from 'preact';
22
import { Link } from 'preact-router';
3-
import { useState, useEffect } from 'preact/hooks';
3+
import { usePrerenderData } from '../../prerender-data-provider';
44
import style from './style';
55

66
const photographs = (props) => {
7-
const [dataResponse, setDataResponse] = useState({});
8-
useEffect(async () => {
9-
setDataResponse(await(await fetch('/source-fs.json')).json());
10-
}, []);
11-
let photographs = [];
12-
if (dataResponse.nodes && dataResponse.nodes[1] && dataResponse.nodes[1].edges) {
13-
photographs = dataResponse.nodes[1].edges;
7+
const [data, isLoading] = usePrerenderData(props);
8+
9+
if (isLoading) {
10+
return (<h1>Loading</h1>);
11+
}
12+
if (data && data.data) {
13+
const { data: { edges: photographs } } = data;
14+
return (
15+
<div class={style.pageBlogs}>
16+
<h1 class={style.pageTitle}>Photographs</h1>
17+
{photographs.map(photograph =>
18+
(<div>
19+
<img class={style.photo} src={photograph.details.photo} />
20+
<caption class={style.caption}>{photograph.details.title}</caption>
21+
</div>)
22+
)}
23+
</div>
24+
);
1425
}
15-
return (
16-
<div class={style.pageBlogs}>
17-
<h1 class={style.pageTitle}>Photographs</h1>
18-
{photographs.map(blog => (
19-
<Link href={`/blog/${blog.id}`}>
20-
<article>
21-
<h2>{blog.details.title}</h2>
22-
<div>
23-
{
24-
(blog.details.tags.substr(1, blog.details.tags.length - 2).split(',') || []).map(tag => <span class={style.tag}>{tag}</span>)
25-
}
26-
</div>
27-
<p class={style.preview}>
28-
{blog.preview}
29-
</p>
30-
</article>
31-
</Link>
32-
))}
33-
</div>
34-
);
26+
return (<h1>Error</h1>);
3527
};
3628

3729
export default photographs;

src/routes/photographs/style.css

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,11 @@
1717
border-bottom: 2px solid #FFC107;
1818
}
1919

20-
h2 {
21-
font-weight: 400;
22-
font-size: 24px;
20+
.photo {
21+
max-width: 100%;
2322
}
2423

25-
.tag {
26-
padding: 8px;
27-
margin-left: 8px;
28-
text-transform: lowercase;
29-
background-color: #ffdd037c;
30-
border-radius: 8px;
31-
color: #999;
32-
font-size: 12px;
33-
}
34-
35-
.tag:first-child {
36-
margin-left: 0px;
37-
}
38-
39-
.preview {
40-
width: 50%;
41-
line-height: 1.3;
42-
color: #666;
43-
max-height: 40px;
44-
overflow: hidden;
45-
text-overflow: ellipsis;
24+
.caption {
25+
font-weight: 300;
26+
display: block;
4627
}

0 commit comments

Comments
 (0)