Skip to content

Commit bb4a82f

Browse files
author
Carlos Rufo Jimenez
committed
2-end-queries-2.0
1 parent 6ddc2da commit bb4a82f

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

src/components/App.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
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'
43

54
class App extends Component {
65
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 />
187
}
198
}
209

21-
export default App;
10+
export default App

src/components/Link.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

src/components/LinkList.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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)

0 commit comments

Comments
 (0)