File tree Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import LinkList from './LinkList'
3
3
import CreateLink from './CreateLink'
4
+ import Header from './Header'
5
+ import { Switch , Route } from 'react-router-dom'
4
6
5
- export default ( ) => < CreateLink />
7
+ export default ( ) => (
8
+ < div className = "center w85" >
9
+ < Header />
10
+ < div className = "ph3 pv1 background-gray" >
11
+ < Switch >
12
+ < Route exact path = "/" component = { LinkList } />
13
+ < Route exact path = "/create" component = { CreateLink } />
14
+ </ Switch >
15
+ </ div >
16
+ </ div >
17
+ )
Original file line number Diff line number Diff line change @@ -39,7 +39,11 @@ class CreateLink extends Component {
39
39
placeholder = "The URL for the link"
40
40
/>
41
41
</ div >
42
- < Mutation mutation = { POST_MUTATION } variables = { { description, url } } >
42
+ < Mutation
43
+ mutation = { POST_MUTATION }
44
+ variables = { { description, url } }
45
+ onCompleted = { ( ) => this . props . history . push ( '/' ) }
46
+ >
43
47
{ postMutation => < button onClick = { postMutation } > Submit</ button > }
44
48
</ Mutation >
45
49
</ div >
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { Link } from 'react-router-dom'
3
+ import { withRouter } from 'react-router'
4
+
5
+ const Header = ( ) => (
6
+ < div className = "flex pa1 justify-between nowrap orange" >
7
+ < div className = "flex flex-fixed black" >
8
+ < div className = "fw7 mr1" > Hacker News</ div >
9
+ < Link to = "/" className = "ml1 no-underline black" >
10
+ new
11
+ </ Link >
12
+ < div className = "ml1" > |</ div >
13
+ < Link to = "/create" className = "ml1 no-underline black" >
14
+ submit
15
+ </ Link >
16
+ </ div >
17
+ </ div >
18
+ )
19
+
20
+ export default withRouter ( Header )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { ApolloProvider } from 'react-apollo'
8
8
import { ApolloClient } from 'apollo-client'
9
9
import { HttpLink } from 'apollo-link-http'
10
10
import { InMemoryCache } from 'apollo-cache-inmemory'
11
+ import { BrowserRouter } from 'react-router-dom'
11
12
12
13
// 2
13
14
const httpLink = new HttpLink ( { uri : 'http://localhost:4000' } )
@@ -20,9 +21,11 @@ const client = new ApolloClient({
20
21
21
22
// 4
22
23
ReactDOM . render (
23
- < ApolloProvider client = { client } >
24
- < App />
25
- </ ApolloProvider >
26
- , document . getElementById ( 'root' )
24
+ < BrowserRouter >
25
+ < ApolloProvider client = { client } >
26
+ < App />
27
+ </ ApolloProvider >
28
+ </ BrowserRouter > ,
29
+ document . getElementById ( 'root' )
27
30
)
28
- registerServiceWorker ( )
31
+ registerServiceWorker ( )
You can’t perform that action at this time.
0 commit comments