-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathListPage.js
More file actions
executable file
·77 lines (69 loc) · 1.89 KB
/
ListPage.js
File metadata and controls
executable file
·77 lines (69 loc) · 1.89 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react'
import { Link } from 'react-router-dom'
import Post from '../components/Post'
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
class ListPage extends React.Component {
componentWillReceiveProps(nextProps) {
if (this.props.location.key !== nextProps.location.key) {
this.props.allPostsQuery.refetch()
}
}
render() {
if (this.props.allPostsQuery.loading) {
return (
<div className='flex w-100 h-100 items-center justify-center pt7'>
<div>
Loading
(from {process.env.REACT_APP_GRAPHQL_ENDPOINT})
</div>
</div>
)
}
let blurClass = ''
if (this.props.location.pathname !== '/') {
blurClass = ' blur'
}
return (
<div className={'w-100 flex justify-center pa6' + blurClass}>
<div className='w-100 flex flex-wrap' style={{maxWidth: 1150}}>
<Link
to='/create'
className='ma3 box new-post br2 flex flex-column items-center justify-center ttu fw6 f2 black-30 no-underline'
>
<img
src={require('../assets/plus.svg')}
alt=''
className='plus mb3'
/>
<div>New Post</div>
</Link>
{this.props.allPostsQuery.allPosts && this.props.allPostsQuery.allPosts.map(post => (
<Post
key={post.id}
post={post}
refresh={() => this.props.allPostsQuery.refetch()}
/>
))}
</div>
{this.props.children}
</div>
)
}
}
const ALL_POSTS_QUERY = gql`
query AllPostsQuery {
allPosts(orderBy: createdAt_DESC) {
id
imageUrl
description
}
}
`
const ListPageWithQuery = graphql(ALL_POSTS_QUERY, {
name: 'allPostsQuery',
options: {
fetchPolicy: 'network-only',
},
})(ListPage)
export default ListPageWithQuery