Skip to content

Commit 7081bb8

Browse files
committed
part 13
1 parent 536823e commit 7081bb8

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/components/App.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from 'react';
22
import './App.css';
3-
3+
import SearchStories from './SearchStories';
44
import Stories from './Stories';
55

66
const App = () =>
77
<div className="app">
8+
<div className="interactions">
9+
<SearchStories />
10+
</div>
811
<Stories />
912
</div>
1013

src/components/SearchStories.js

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

0 commit comments

Comments
 (0)