Skip to content

Commit

Permalink
part 13
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Sep 1, 2017
1 parent 536823e commit 7081bb8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import './App.css';

import SearchStories from './SearchStories';
import Stories from './Stories';

const App = () =>
<div className="app">
<div className="interactions">
<SearchStories />
</div>
<Stories />
</div>

Expand Down
51 changes: 51 additions & 0 deletions src/components/SearchStories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { Component } from 'react';
import { observable, action } from 'mobx';
import { observer } from 'mobx-react';
import Button from './Button';

@observer
class SearchStories extends Component {
@observable query = '';

constructor(props) {
super(props);

this.onSubmit = this.onSubmit.bind(this);
this.onChange = this.onChange.bind(this);
}

@action
onChange(event) {
const { value } = event.target;
this.query = value;
}

@action
onSubmit(event) {
if (this.query) {
// TODO do API fetch stories
console.log(this.query);

this.query = '';
}

event.preventDefault();
}

render() {
return (
<form onSubmit={this.onSubmit}>
<input
type="text"
value={this.query}
onChange={this.onChange}
/>
<Button type="submit">
Search
</Button>
</form>
);
}
}

export default SearchStories;

0 comments on commit 7081bb8

Please sign in to comment.