Commit d5bd8c7d authored by Adam Soffer's avatar Adam Soffer Committed by Tim Neutkens

Update with-apollo example (#1394)

* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* Update Apollo example

* Remove trailing comma

* Update reduxRootKey

* Remove unnecessary babelrc

* Update with-apollo example

- Remove use of deprecated 'reduxRootKey' option
- Add loading indicator inside pagination button
parent 68a7b59b
...@@ -4,12 +4,8 @@ import PostUpvoter from './PostUpvoter' ...@@ -4,12 +4,8 @@ import PostUpvoter from './PostUpvoter'
const POSTS_PER_PAGE = 10 const POSTS_PER_PAGE = 10
function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts }) { function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts }) {
if (loading) { if (allPosts && allPosts.length) {
return <div>Loading</div>
}
const areMorePosts = allPosts.length < _allPostsMeta.count const areMorePosts = allPosts.length < _allPostsMeta.count
return ( return (
<section> <section>
<ul> <ul>
...@@ -23,7 +19,7 @@ function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts } ...@@ -23,7 +19,7 @@ function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts }
</li> </li>
)} )}
</ul> </ul>
{areMorePosts ? <button onClick={() => loadMorePosts()}><span />Show More</button> : ''} {areMorePosts ? <button onClick={() => loadMorePosts()}> {loading ? 'Loading...' : 'Show More'} </button> : ''}
<style jsx>{` <style jsx>{`
section { section {
padding-bottom: 20px; padding-bottom: 20px;
...@@ -58,11 +54,14 @@ function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts } ...@@ -58,11 +54,14 @@ function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts }
border-color: #ffffff transparent transparent transparent; border-color: #ffffff transparent transparent transparent;
content: ""; content: "";
height: 0; height: 0;
margin-right: 5px;
width: 0; width: 0;
} }
`}</style> `}</style>
</section> </section>
) )
}
return <div>Loading</div>
} }
const allPosts = gql` const allPosts = gql`
......
...@@ -26,10 +26,11 @@ export default (Component) => ( ...@@ -26,10 +26,11 @@ export default (Component) => (
} }
const state = store.getState() const state = store.getState()
return { return {
initialState: { initialState: {
...state, ...state,
[client.reduxRootKey]: { apollo: {
data: client.getInitialState().data data: client.getInitialState().data
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment