@@ -23,49 +23,40 @@ const VOTE_MUTATION = gql`
2323 }
2424`
2525
26- class Link extends Component {
27- render ( ) {
28- const authToken = localStorage . getItem ( AUTH_TOKEN )
29- const { link : { id : linkId } } = this . props
30- return (
31- < div className = "flex mt2 items-start" >
32- < div className = "flex items-center" >
33- < span className = "gray" > { this . props . index + 1 } .</ span >
34- { authToken && (
35- < Mutation
36- mutation = { VOTE_MUTATION }
37- variables = { { linkId } }
38- update = { ( cache , { data : { vote } } ) =>
39- this . props . updateStoreAfterVote ( cache , vote , linkId )
40- }
41- >
42- { voteMutation => (
43- < div className = "ml1 gray f11" onClick = { voteMutation } >
44- ▲
45- </ div >
46- ) }
47- </ Mutation >
48- ) }
26+ export default props => {
27+ const authToken = localStorage . getItem ( AUTH_TOKEN )
28+ const {
29+ link : { id : linkId , description, url, votes, postedBy, createdAt } ,
30+ } = props
31+ return (
32+ < div className = "flex mt2 items-start" >
33+ < div className = "flex items-center" >
34+ < span className = "gray" > { props . index + 1 } .</ span >
35+ { authToken && (
36+ < Mutation
37+ mutation = { VOTE_MUTATION }
38+ variables = { { linkId } }
39+ update = { ( cache , { data : { vote } } ) =>
40+ props . updateStoreAfterVote ( cache , vote , linkId )
41+ }
42+ >
43+ { voteMutation => (
44+ < div className = "ml1 gray f11" onClick = { voteMutation } >
45+ ▲
46+ </ div >
47+ ) }
48+ </ Mutation >
49+ ) }
50+ </ div >
51+ < div className = "ml1" >
52+ < div >
53+ { description } ({ url } )
4954 </ div >
50- < div className = "ml1" >
51- < div >
52- { this . props . link . description } ({ this . props . link . url } )
53- </ div >
54- < div className = "f6 lh-copy gray" >
55- { this . props . link . votes . length } votes | by{ ' ' }
56- { this . props . link . postedBy
57- ? this . props . link . postedBy . name
58- : 'Unknown' } { ' ' }
59- { timeDifferenceForDate ( this . props . link . createdAt ) }
60- </ div >
55+ < div className = "f6 lh-copy gray" >
56+ { votes . length } votes | by { postedBy ? postedBy . name : 'Unknown' }
57+ { timeDifferenceForDate ( createdAt ) }
6158 </ div >
6259 </ div >
63- )
64- }
65-
66- _voteForLink = async ( ) => {
67- // ... you'll implement this in chapter 6
68- }
60+ </ div >
61+ )
6962}
70-
71- export default Link
0 commit comments