Skip to content

Commit 28d0999

Browse files
author
Carlos Rufo Jimenez
committed
🚀
2 parents 10e6041 + def3256 commit 28d0999

File tree

11 files changed

+245
-280
lines changed

11 files changed

+245
-280
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"private": true,
55
"dependencies": {
66
"apollo-client-preset": "^1.0.8",
7+
"apollo-link-context": "^1.0.7",
78
"apollo-link-ws": "^1.0.7",
89
"graphql": "^0.13.1",
910
"graphql-tag": "^2.8.0",
1011
"react": "^16.2.0",
11-
"react-apollo": "^2.1.0-beta.3",
12+
"react-apollo": "^2.1.0",
1213
"react-dom": "^16.2.0",
1314
"react-router": "^4.2.0",
1415
"react-router-dom": "^4.2.2",

src/components/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import LinkList from './LinkList'
33
import CreateLink from './CreateLink'
44
import Header from './Header'
@@ -12,8 +12,8 @@ export default () => (
1212
<div className="ph3 pv1 background-gray">
1313
<Switch>
1414
<Route exact path="/" render={() => <Redirect to="/new/1" />} />
15-
<Route exact path="/login" component={Login} />
1615
<Route exact path="/create" component={CreateLink} />
16+
<Route exact path="/login" component={Login} />
1717
<Route exact path="/search" component={Search} />
1818
<Route exact path="/top" component={LinkList} />
1919
<Route exact path="/new/:page" component={LinkList} />

src/components/CreateLink.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const POST_MUTATION = gql`
2828
class CreateLink extends Component {
2929
state = {
3030
description: '',
31-
url: '',
31+
url: ''
3232
}
3333

3434
render() {
@@ -54,32 +54,25 @@ class CreateLink extends Component {
5454
<Mutation
5555
mutation={POST_MUTATION}
5656
variables={{ description, url }}
57+
onCompleted={() => this.props.history.push('/new/1')}
5758
update={(cache, { data: { post } }) => {
5859
const first = LINKS_PER_PAGE
5960
const skip = 0
6061
const orderBy = 'createdAt_DESC'
6162
const data = cache.readQuery({
6263
query: FEED_QUERY,
63-
variables: { first, skip, orderBy },
64+
variables: { first, skip, orderBy }
6465
})
65-
data.feed.links.splice(0, 0, post)
66+
data.feed.links.unshift(post)
6667
data.feed.links.pop()
6768
cache.writeQuery({
6869
query: FEED_QUERY,
6970
data,
70-
variables: { first, skip, orderBy },
71+
variables: { first, skip, orderBy }
7172
})
7273
}}
7374
>
74-
{postMutation => (
75-
<button
76-
onClick={() =>
77-
postMutation() && this.props.history.push(`/new/1`)
78-
}
79-
>
80-
Submit
81-
</button>
82-
)}
75+
{postMutation => <button onClick={postMutation}>Submit</button>}
8376
</Mutation>
8477
</div>
8578
)

src/components/Header.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import { Link } from 'react-router-dom'
33
import { withRouter } from 'react-router'
44
import { AUTH_TOKEN } from '../constants'
55

6-
const Header = () => {
6+
const Header = props => {
77
const authToken = localStorage.getItem(AUTH_TOKEN)
88
return (
99
<div className="flex pa1 justify-between nowrap orange">
@@ -35,7 +35,7 @@ const Header = () => {
3535
className="ml1 pointer black"
3636
onClick={() => {
3737
localStorage.removeItem(AUTH_TOKEN)
38-
this.props.history.push(`/`)
38+
props.history.push(`/`)
3939
}}
4040
>
4141
logout

src/components/Link.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import { AUTH_TOKEN } from '../constants'
33
import { timeDifferenceForDate } from '../utils'
44
import { Mutation } from 'react-apollo'
@@ -23,21 +23,18 @@ const VOTE_MUTATION = gql`
2323
}
2424
`
2525

26-
export default props => {
26+
export default ({ link, index, updateStoreAfterVote }) => {
2727
const authToken = localStorage.getItem(AUTH_TOKEN)
28-
const {
29-
link: { id: linkId, description, url, votes, postedBy, createdAt },
30-
} = props
3128
return (
3229
<div className="flex mt2 items-start">
3330
<div className="flex items-center">
34-
<span className="gray">{props.index + 1}.</span>
31+
<span className="gray">{index + 1}.</span>
3532
{authToken && (
3633
<Mutation
3734
mutation={VOTE_MUTATION}
38-
variables={{ linkId }}
35+
variables={{ linkId: link.id }}
3936
update={(cache, { data: { vote } }) =>
40-
props.updateStoreAfterVote(cache, vote, linkId)
37+
updateStoreAfterVote(cache, vote, link.id)
4138
}
4239
>
4340
{voteMutation => (
@@ -50,11 +47,12 @@ export default props => {
5047
</div>
5148
<div className="ml1">
5249
<div>
53-
{description} ({url})
50+
{link.description} ({link.url})
5451
</div>
5552
<div className="f6 lh-copy gray">
56-
{votes.length} votes | by {postedBy ? postedBy.name : 'Unknown'}
57-
{timeDifferenceForDate(createdAt)}
53+
{`${link.votes.length} votes | by
54+
${link.postedBy ? link.postedBy.name : 'Unknown'}
55+
${timeDifferenceForDate(link.createdAt)}`}
5856
</div>
5957
</div>
6058
</div>

0 commit comments

Comments
 (0)