File tree Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import LinkList from './LinkList'
3
3
import CreateLink from './CreateLink'
4
4
import Header from './Header'
5
5
import Login from './Login'
6
+ import Search from './Search'
6
7
import { Switch , Route } from 'react-router-dom'
7
8
8
9
class App extends Component {
@@ -12,9 +13,10 @@ class App extends Component {
12
13
< Header />
13
14
< div className = "ph3 pv1 background-gray" >
14
15
< Switch >
15
- < Route exact path = "/login" component = { Login } />
16
16
< Route exact path = "/" component = { LinkList } />
17
17
< Route exact path = "/create" component = { CreateLink } />
18
+ < Route exact path = "/login" component = { Login } />
19
+ < Route exact path = "/search" component = { Search } />
18
20
</ Switch >
19
21
</ div >
20
22
</ div >
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ class Header extends Component {
13
13
< Link to = "/" className = "ml1 no-underline black" >
14
14
new
15
15
</ Link >
16
+ < div className = "ml1" > |</ div >
17
+ < Link to = "/search" className = "ml1 no-underline black" >
18
+ search
19
+ </ Link >
16
20
{ authToken && (
17
21
< div className = "flex" >
18
22
< div className = "ml1" > |</ div >
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react'
2
+ import { withApollo } from 'react-apollo'
3
+ import gql from 'graphql-tag'
4
+ import Link from './Link'
5
+
6
+ const FEED_SEARCH_QUERY = gql `
7
+ query FeedSearchQuery($filter: String!) {
8
+ feed(filter: $filter) {
9
+ links {
10
+ id
11
+ url
12
+ description
13
+ createdAt
14
+ postedBy {
15
+ id
16
+ name
17
+ }
18
+ votes {
19
+ id
20
+ user {
21
+ id
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ `
28
+
29
+ class Search extends Component {
30
+ state = {
31
+ links : [ ] ,
32
+ filter : '' ,
33
+ }
34
+
35
+ render ( ) {
36
+ return (
37
+ < div >
38
+ < div >
39
+ Search
40
+ < input
41
+ type = "text"
42
+ onChange = { e => this . setState ( { filter : e . target . value } ) }
43
+ />
44
+ < button onClick = { ( ) => this . _executeSearch ( ) } > OK</ button >
45
+ </ div >
46
+ { this . state . links . map ( ( link , index ) => (
47
+ < Link key = { link . id } link = { link } index = { index } />
48
+ ) ) }
49
+ </ div >
50
+ )
51
+ }
52
+
53
+ _executeSearch = async ( ) => {
54
+ const { filter } = this . state
55
+ const result = await this . props . client . query ( {
56
+ query : FEED_SEARCH_QUERY ,
57
+ variables : { filter } ,
58
+ } )
59
+ const links = result . data . feed . links
60
+ this . setState ( { links } )
61
+ }
62
+ }
63
+
64
+ export default withApollo ( Search )
You can’t perform that action at this time.
0 commit comments