-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathDraftsPage.js
More file actions
61 lines (56 loc) · 1.41 KB
/
DraftsPage.js
File metadata and controls
61 lines (56 loc) · 1.41 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
import React, { Component, Fragment } from 'react'
import Post from '../components/Post'
import { graphql } from 'react-apollo'
import { gql } from 'apollo-boost'
class DraftsPage extends Component {
componentWillReceiveProps(nextProps) {
if (this.props.location.key !== nextProps.location.key) {
this.props.draftsQuery.refetch()
}
}
render() {
if (this.props.draftsQuery.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>
)
}
return (
<Fragment>
<div className="flex justify-between items-center">
<h1>Drafts</h1>
</div>
{this.props.draftsQuery.drafts &&
this.props.draftsQuery.drafts.map(draft => (
<Post
key={draft.id}
post={draft}
refresh={() => this.props.draftsQuery.refetch()}
isDraft={!draft.published}
/>
))}
{this.props.children}
</Fragment>
)
}
}
const DRAFTS_QUERY = gql`
query DraftsQuery {
drafts {
id
content
title
published
author {
name
}
}
}
`
export default graphql(DRAFTS_QUERY, {
name: 'draftsQuery', // name of the injected prop: this.props.feedQuery...
options: {
fetchPolicy: 'network-only',
},
})(DraftsPage)