Skip to content

Commit d5bd8c7

Browse files
adamsoffertimneutkens
authored andcommitted
Update with-apollo example (vercel#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
1 parent 68a7b59 commit d5bd8c7

File tree

2 files changed

+59
-59
lines changed

2 files changed

+59
-59
lines changed

examples/with-apollo/components/PostList.js

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,64 @@ import PostUpvoter from './PostUpvoter'
44
const POSTS_PER_PAGE = 10
55

66
function PostList ({ data: { allPosts, loading, _allPostsMeta }, loadMorePosts }) {
7-
if (loading) {
8-
return <div>Loading</div>
7+
if (allPosts && allPosts.length) {
8+
const areMorePosts = allPosts.length < _allPostsMeta.count
9+
return (
10+
<section>
11+
<ul>
12+
{allPosts.map((post, index) =>
13+
<li key={post.id}>
14+
<div>
15+
<span>{index + 1}. </span>
16+
<a href={post.url}>{post.title}</a>
17+
<PostUpvoter id={post.id} votes={post.votes} />
18+
</div>
19+
</li>
20+
)}
21+
</ul>
22+
{areMorePosts ? <button onClick={() => loadMorePosts()}> {loading ? 'Loading...' : 'Show More'} </button> : ''}
23+
<style jsx>{`
24+
section {
25+
padding-bottom: 20px;
26+
}
27+
li {
28+
display: block;
29+
margin-bottom: 10px;
30+
}
31+
div {
32+
align-items: center;
33+
display: flex;
34+
}
35+
a {
36+
font-size: 14px;
37+
margin-right: 10px;
38+
text-decoration: none;
39+
padding-bottom: 0;
40+
border: 0;
41+
}
42+
span {
43+
font-size: 14px;
44+
margin-right: 5px;
45+
}
46+
ul {
47+
margin: 0;
48+
padding: 0;
49+
}
50+
button:before {
51+
align-self: center;
52+
border-style: solid;
53+
border-width: 6px 4px 0 4px;
54+
border-color: #ffffff transparent transparent transparent;
55+
content: "";
56+
height: 0;
57+
margin-right: 5px;
58+
width: 0;
59+
}
60+
`}</style>
61+
</section>
62+
)
963
}
10-
11-
const areMorePosts = allPosts.length < _allPostsMeta.count
12-
13-
return (
14-
<section>
15-
<ul>
16-
{allPosts.map((post, index) =>
17-
<li key={post.id}>
18-
<div>
19-
<span>{index + 1}. </span>
20-
<a href={post.url}>{post.title}</a>
21-
<PostUpvoter id={post.id} votes={post.votes} />
22-
</div>
23-
</li>
24-
)}
25-
</ul>
26-
{areMorePosts ? <button onClick={() => loadMorePosts()}><span />Show More</button> : ''}
27-
<style jsx>{`
28-
section {
29-
padding-bottom: 20px;
30-
}
31-
li {
32-
display: block;
33-
margin-bottom: 10px;
34-
}
35-
div {
36-
align-items: center;
37-
display: flex;
38-
}
39-
a {
40-
font-size: 14px;
41-
margin-right: 10px;
42-
text-decoration: none;
43-
padding-bottom: 0;
44-
border: 0;
45-
}
46-
span {
47-
font-size: 14px;
48-
margin-right: 5px;
49-
}
50-
ul {
51-
margin: 0;
52-
padding: 0;
53-
}
54-
button:before {
55-
align-self: center;
56-
border-style: solid;
57-
border-width: 6px 4px 0 4px;
58-
border-color: #ffffff transparent transparent transparent;
59-
content: "";
60-
height: 0;
61-
width: 0;
62-
}
63-
`}</style>
64-
</section>
65-
)
64+
return <div>Loading</div>
6665
}
6766

6867
const allPosts = gql`

examples/with-apollo/lib/withData.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export default (Component) => (
2626
}
2727

2828
const state = store.getState()
29+
2930
return {
3031
initialState: {
3132
...state,
32-
[client.reduxRootKey]: {
33+
apollo: {
3334
data: client.getInitialState().data
3435
}
3536
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy