Last active
February 20, 2017 23:18
-
-
Save RyanCCollins/d43df0f04d38c0e5478bbbbc8a88092a to your computer and use it in GitHub Desktop.
Blog container
This file contains hidden or 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 * as React from 'react'; | |
import { graphql } from 'react-apollo'; | |
import { Headline, LoadingIndicator, PostCard, Section, Box } from 'components'; | |
import POST_QUERY from './posts.graphql'; | |
import { StyledHr } from './styles'; | |
interface IPost { | |
id: string; | |
title: string; | |
image: string; | |
content: string; | |
} | |
interface IBlogProps extends React.Props<any> { | |
loading: boolean; | |
error?: { message: string }; | |
posts?: IPost[]; | |
}; | |
type IBlogPropTypes = IBlogProps; | |
class Blog extends React.Component<IBlogPropTypes, any> { | |
public render() { | |
const { loading, posts, error } = this.props; | |
return ( | |
<Box | |
alignItems="center" | |
flexDirection="column" | |
pad={{ vertical: 'medium', horizontal: 'small' }} | |
full={{ vertical: true }} | |
backgroundColor="#f5f5f5" | |
> | |
<Headline> | |
Blog | |
<StyledHr /> | |
</Headline> | |
{error && | |
<Box | |
backgroundColor="#ff324d" | |
size={{ horizontal: 'medium' }} | |
pad="small" | |
alignItems="center" | |
> | |
<p style={{ color: 'white' }}>{error.message}</p> | |
</Box> | |
} | |
<LoadingIndicator isLoading={loading} /> | |
<Section | |
wrap | |
justifyContent="center" | |
alignItems="center" | |
flexDirection="row" | |
size={{ horizontal: 'full' }} | |
> | |
{posts && posts.map((item, i) => | |
<Box key={i} pad="medium"> | |
<PostCard | |
{...item} | |
/> | |
</Box>, | |
)} | |
</Section> | |
</Box> | |
); | |
} | |
} | |
const withData = graphql(POST_QUERY, { | |
props: ({ data: { loading, posts, error } }) => ({ | |
loading, | |
posts, | |
error, | |
}), | |
}); | |
export default withData(Blog); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment