File tree Expand file tree Collapse file tree 3 files changed +66
-15
lines changed Expand file tree Collapse file tree 3 files changed +66
-15
lines changed Original file line number Diff line number Diff line change 1
- import React , { Component } from 'react' ;
2
- import logo from '../logo.svg' ;
3
- import '../styles/App.css' ;
1
+ import React , { Component } from 'react'
2
+ import LinkList from './LinkList'
4
3
5
4
class App extends Component {
6
5
render ( ) {
7
- return (
8
- < div className = "App" >
9
- < header className = "App-header" >
10
- < img src = { logo } className = "App-logo" alt = "logo" />
11
- < h1 className = "App-title" > Welcome to React</ h1 >
12
- </ header >
13
- < p className = "App-intro" >
14
- To get started, edit < code > src/App.js</ code > and save to reload.
15
- </ p >
16
- </ div >
17
- ) ;
6
+ return < LinkList />
18
7
}
19
8
}
20
9
21
- export default App ;
10
+ export default App
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react'
2
+
3
+ class Link extends Component {
4
+ render ( ) {
5
+ return (
6
+ < div >
7
+ < div >
8
+ { this . props . link . description } ({ this . props . link . url } )
9
+ </ div >
10
+ </ div >
11
+ )
12
+ }
13
+
14
+ _voteForLink = async ( ) => {
15
+ // ... you'll implement this in chapter 6
16
+ }
17
+ }
18
+
19
+ export default Link
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react'
2
+ import Link from './Link'
3
+ import { graphql } from 'react-apollo'
4
+ import gql from 'graphql-tag'
5
+
6
+ class LinkList extends Component {
7
+ render ( ) {
8
+ // 1
9
+ if ( this . props . feedQuery && this . props . feedQuery . loading ) {
10
+ return < div > Loading</ div >
11
+ }
12
+
13
+ // 2
14
+ if ( this . props . feedQuery && this . props . feedQuery . error ) {
15
+ return < div > Error</ div >
16
+ }
17
+
18
+ // 3
19
+ const linksToRender = this . props . feedQuery . feed . links
20
+
21
+ return (
22
+ < div > { linksToRender . map ( link => < Link key = { link . id } link = { link } /> ) } </ div >
23
+ )
24
+ }
25
+ }
26
+
27
+ // 1
28
+ const FEED_QUERY = gql `
29
+ # 2
30
+ query FeedQuery {
31
+ feed {
32
+ links {
33
+ id
34
+ createdAt
35
+ url
36
+ description
37
+ }
38
+ }
39
+ }
40
+ `
41
+
42
+ // 3
43
+ export default graphql ( FEED_QUERY , { name : 'feedQuery' } ) ( LinkList )
You can’t perform that action at this time.
0 commit comments