Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.