Skip to content

Commit

Permalink
add clear movies button
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckstock committed Jan 19, 2017
1 parent d59af34 commit de0b62c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/actions/index.js
Expand Up @@ -8,3 +8,9 @@ export const fetchMovies = (term) => {
payload: request
}
}

export const clearMovies = () => {
return {
type: 'CLEAR_MOVIES'
}
}
6 changes: 6 additions & 0 deletions src/components/App.jsx
Expand Up @@ -17,6 +17,12 @@ class App extends Component {
<div className="container">
<h1>OMDB Movie Search</h1>
<SearchBar searchMovie={this.props.fetchMovies.bind(this)} />
<button
className="btn btn-primary clear"
onClick={this.props.clearMovies}
>
Clear Movies
</button>
<MovieList movies={this.props.movies} />
</div>
)
Expand Down
12 changes: 6 additions & 6 deletions src/reducers/movie.reducer.js
@@ -1,11 +1,11 @@
const movieReducer = (state = [], action) => {
console.log(action);
switch (action.type) {
case 'FETCH_MOVIES':
return action.payload.data.Search;
default:
return state;
if (action.type === 'FETCH_MOVIES') {
return action.payload.data.Search;
} else if (action.type === 'CLEAR_MOVIES') {
return [];
}

return state;
}

export default movieReducer;
4 changes: 4 additions & 0 deletions src/stylesheets/index.css
@@ -1,3 +1,7 @@
#root {
text-align: center
}

.clear {
margin-bottom: 20px;
}

0 comments on commit de0b62c

Please sign in to comment.