-
Notifications
You must be signed in to change notification settings - Fork 10
/
Layout.js
43 lines (41 loc) · 1.07 KB
/
Layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { PropTypes } from 'react'
import Picker from '../components/Picker'
import Posts from '../components/Posts'
export default function Layout(_, { posts, isFetching, lastUpdated, onRefresh }) {
return (
<div>
<Picker options={[ 'reactjs', 'frontend' ]} />
<p>
{lastUpdated &&
<span>
Last updated at {new Date(lastUpdated).toLocaleTimeString()}.
{' '}
</span>
}
{!isFetching &&
<a href="#"
onClick={ e => { e.preventDefault(); onRefresh() } }>
Refresh
</a>
}
</p>
{isFetching && posts.length === 0 &&
<h2>Loading...</h2>
}
{!isFetching && posts.length === 0 &&
<h2>Empty.</h2>
}
{posts.length > 0 &&
<div style={{ opacity: isFetching ? 0.5 : 1 }}>
<Posts />
</div>
}
</div>
)
}
Layout.contextTypes = {
posts: PropTypes.array.isRequired,
isFetching: PropTypes.bool.isRequired,
lastUpdated: PropTypes.number,
onRefresh: PropTypes.func.isRequired
}