Created
March 26, 2018 15:24
-
-
Save gc-codesnippets/52e9fcfc38606e2b23b24912d325232a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, Fragment } from 'react' | |
import Post from '../components/Post' | |
import { Query } from 'react-apollo' | |
import gql from 'graphql-tag' | |
export default class FeedPage extends Component { | |
render() { | |
return ( | |
<Query query={FEED_QUERY}> | |
{({ data, loading, error, refetch }) => { | |
if (loading) { | |
return ( | |
<div className="flex w-100 h-100 items-center justify-center pt7"> | |
<div>Loading ...</div> | |
</div> | |
) | |
} | |
if (error) { | |
return ( | |
<div className="flex w-100 h-100 items-center justify-center pt7"> | |
<div>An unexpected error occured.</div> | |
</div> | |
) | |
} | |
return ( | |
<Fragment> | |
<h1>Feed</h1> | |
{data.feed && | |
data.feed.map(post => ( | |
<Post | |
key={post.id} | |
post={post} | |
refresh={() => refetch()} | |
isDraft={!post.isPublished} | |
/> | |
))} | |
{this.props.children} | |
</Fragment> | |
) | |
}} | |
</Query> | |
) | |
} | |
} | |
export const FEED_QUERY = gql` | |
query FeedQuery { | |
feed { | |
id | |
text | |
title | |
isPublished | |
} | |
} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment