File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import CreateLink from './CreateLink'
4
4
import Header from './Header'
5
5
import { Switch , Route } from 'react-router-dom'
6
6
import Login from './Login'
7
+ import Search from './Search'
7
8
8
9
export default ( ) => (
9
10
< div className = "center w85" >
@@ -13,6 +14,7 @@ export default () => (
13
14
< Route exact path = "/" component = { LinkList } />
14
15
< Route exact path = "/create" component = { CreateLink } />
15
16
< Route exact path = "/login" component = { Login } />
17
+ < Route exact path = "/search" component = { Search } />
16
18
</ Switch >
17
19
</ div >
18
20
</ div >
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ const Header = props => {
12
12
< Link to = "/" className = "ml1 no-underline black" >
13
13
new
14
14
</ Link >
15
+ < div className = "ml1" > |</ div >
16
+ < Link to = "/search" className = "ml1 no-underline black" >
17
+ search
18
+ </ Link >
15
19
{ authToken && (
16
20
< div className = "flex" >
17
21
< 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
+ _executeSearch = async ( ) => {
36
+ const { filter } = this . state
37
+ const result = await this . props . client . query ( {
38
+ query : FEED_SEARCH_QUERY ,
39
+ variables : { filter }
40
+ } )
41
+ const links = result . data . feed . links
42
+ this . setState ( { links } )
43
+ }
44
+
45
+ render ( ) {
46
+ return (
47
+ < div >
48
+ < div >
49
+ Search
50
+ < input
51
+ type = "text"
52
+ onChange = { e => this . setState ( { filter : e . target . value } ) }
53
+ />
54
+ < button onClick = { ( ) => this . _executeSearch ( ) } > OK</ button >
55
+ </ div >
56
+ { this . state . links . map ( ( link , index ) => (
57
+ < Link key = { link . id } link = { link } index = { index } />
58
+ ) ) }
59
+ </ div >
60
+ )
61
+ }
62
+ }
63
+
64
+ export default withApollo ( Search )
You can’t perform that action at this time.
0 commit comments