File tree Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import './App.css' ;
3
-
3
+ import SearchStories from './SearchStories' ;
4
4
import Stories from './Stories' ;
5
5
6
6
const App = ( ) =>
7
7
< div className = "app" >
8
+ < div className = "interactions" >
9
+ < SearchStories />
10
+ </ div >
8
11
< Stories />
9
12
</ div >
10
13
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ import { observable , action } from 'mobx' ;
3
+ import { observer } from 'mobx-react' ;
4
+ import Button from './Button' ;
5
+
6
+ @observer
7
+ class SearchStories extends Component {
8
+ @observable query = '' ;
9
+
10
+ constructor ( props ) {
11
+ super ( props ) ;
12
+
13
+ this . onSubmit = this . onSubmit . bind ( this ) ;
14
+ this . onChange = this . onChange . bind ( this ) ;
15
+ }
16
+
17
+ @action
18
+ onChange ( event ) {
19
+ const { value } = event . target ;
20
+ this . query = value ;
21
+ }
22
+
23
+ @action
24
+ onSubmit ( event ) {
25
+ if ( this . query ) {
26
+ // TODO do API fetch stories
27
+ console . log ( this . query ) ;
28
+
29
+ this . query = '' ;
30
+ }
31
+
32
+ event . preventDefault ( ) ;
33
+ }
34
+
35
+ render ( ) {
36
+ return (
37
+ < form onSubmit = { this . onSubmit } >
38
+ < input
39
+ type = "text"
40
+ value = { this . query }
41
+ onChange = { this . onChange }
42
+ />
43
+ < Button type = "submit" >
44
+ Search
45
+ </ Button >
46
+ </ form >
47
+ ) ;
48
+ }
49
+ }
50
+
51
+ export default SearchStories ;
You can’t perform that action at this time.
0 commit comments