Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 75bfabe

Browse files
author
Rizchel Dayao
committed
Make code more clear and easy to follow
1 parent c34a822 commit 75bfabe

File tree

11 files changed

+61
-77
lines changed

11 files changed

+61
-77
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "React Redux API Example",
2+
"name": "MovieFinder",
33
"version": "0.0.1",
44
"description": "React Redux application that calls the OMDb api to get information on a specific movie",
55
"repository": "git+https://github.com/rizcheldayao/react-redux-api-example",

src/actions/index.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import fetch from 'isomorphic-fetch';
22
import ActionTypes from '../constants';
33

4-
export const setResults = (result) => ({
5-
type: ActionTypes.SET_RESULTS,
6-
payload: {
7-
result
8-
},
9-
});
10-
114
function retrieveMoviesStart() {
125
return {
136
type: ActionTypes.RETRIEVE_MOVIES_START,
@@ -17,24 +10,21 @@ function retrieveMoviesStart() {
1710
function retrieveMoviesError(error) {
1811
return {
1912
type: ActionTypes.RETRIEVE_MOVIES_ERROR,
20-
payload: {
21-
error
22-
}
13+
payload: error
2314
};
2415
}
2516

2617
function retrieveMoviesSuccess(response) {
2718
return {
2819
type: ActionTypes.RETRIEVE_MOVIES_SUCCESS,
29-
payload:
30-
response
20+
payload: response
3121
};
3222
}
3323

3424
export function retrieveMovies(userInput) {
3525
return dispatch => {
3626
// Insert your api key on line 30
37-
const URL = `http://www.omdbapi.com/?apikey=[apiKey]&t=${userInput}`;
27+
const URL = `http://www.omdbapi.com/?apikey=d8c6a83b&t=${userInput}`;
3828
let request = new Request(URL, {
3929
method: 'GET',
4030
});

src/components/ListItem.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { PropTypes, Component } from 'react';
2+
import { connect } from 'react-redux';
3+
import '../style/main.css';
4+
5+
class ListItem extends Component {
6+
render() {
7+
const { list } = this.props;
8+
return (
9+
<div className="list-item">
10+
<ul>
11+
{list}
12+
</ul>
13+
</div>
14+
);
15+
}
16+
}
17+
18+
ListItem.PropTypes = {
19+
list: PropTypes.array,
20+
}
21+
22+
export default ListItem;

src/constants/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export default {
22
RETRIEVE_MOVIES_START:'RETRIEVE_MOVIES_START',
33
RETRIEVE_MOVIES_ERROR:'RETRIEVE_MOVIES_ERROR',
4-
RETRIEVE_MOVIES_SUCCESS:'RETRIEVE_MOVIES_SUCCESS',
5-
SET_RESULTS:'SET_RESULTS'
4+
RETRIEVE_MOVIES_SUCCESS:'RETRIEVE_MOVIES_SUCCESS'
65
};

src/containers/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component, PropTypes } from 'react'
22
import { connect } from 'react-redux'
3-
import List from '../components/List'
3+
import List from './List'
44
import InputSet from './InputSet';
55
import * as MoviesAction from '../actions'
66
import { bindActionCreators } from 'redux'
@@ -11,9 +11,9 @@ class App extends Component {
1111
render() {
1212
return (
1313
<div className="container">
14-
<h1>Find That Movie</h1>
14+
<h1>Movie Finder</h1>
1515
<InputSet />
16-
<List movies={this.props.movies} />
16+
<List />
1717
</div>
1818
);
1919
}

src/containers/InputSet.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class InputSet extends Component {
1010
super(props)
1111
this.state = {
1212
input: '',
13-
// result: {}
1413
}
1514

1615
this.handleKeyPress = this.handleKeyPress.bind(this)
@@ -19,12 +18,8 @@ class InputSet extends Component {
1918
}
2019

2120
handleResponse(input) {
22-
const { retrieveMovies, setResults } = this.props;
21+
const { retrieveMovies } = this.props;
2322
const result = retrieveMovies(input);
24-
// this.setState({
25-
// result: result
26-
// })
27-
setResults(result);
2823
}
2924

3025
handleChange(e) {
@@ -51,8 +46,7 @@ class InputSet extends Component {
5146

5247
InputSet.propTypes = {
5348
movies: PropTypes.object,
54-
retrieveMovies: PropTypes.func,
55-
setResults: PropTypes.func,
49+
retrieveMovies: PropTypes.func
5650
}
5751

5852
function mapStateToProps(state) {
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import React, { PropTypes, Component } from 'react';
22
import { connect } from 'react-redux';
33
import '../style/main.css';
4+
import ListItem from '../components/ListItem';
5+
import createList from '../utils';
46

57
class List extends Component {
68
render() {
7-
var myList = [];
8-
for (var prop in this.props.movies.items) {
9-
if(myList.length < 13) {
10-
myList.push(<li key={prop}><p>{`${prop}: ${this.props.movies.items[prop]}`}</p></li>);
11-
}
12-
}
9+
const { movies } = this.props;
10+
const myList = createList(movies);
1311
return (
1412
<div className="list">
15-
<ul>
16-
{myList}
17-
</ul>
13+
{myList.length > 0 && <ListItem list={myList} />}
1814
</div>
1915
);
2016
}

src/reducers/index.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,13 @@
1-
// import { combineReducers } from 'redux'
2-
import ActionTypes from '../constants'
31
import { combineReducers } from 'redux';
42
import { routerStateReducer } from 'redux-router';
3+
import ActionTypes from '../constants'
54

65
const initialState = {
76
isFetching: false,
87
items: [],
9-
errorDetails: '',
10-
result: ''
8+
errorDetails: ''
119
};
1210

13-
// export const handlers = {
14-
// [ActionTypes.RETRIEVE_MOVIES_START](state, action) {
15-
// return {
16-
// ...state,
17-
// isFetching: true,
18-
// };
19-
// },
20-
// [ActionTypes.RETRIEVE_MOVIES_ERROR](state, action) {
21-
// return {
22-
// ...state,
23-
// isFetching: false,
24-
// errorDetails: action.payload.error,
25-
// };
26-
// },
27-
// [ActionTypes.RETRIEVE_MOVIES_SUCCESS](state, action) {
28-
// return {
29-
// ...state,
30-
// isFetching: false,
31-
// items: action.payload.response,
32-
// };
33-
// },
34-
// [ActionTypes.RETRIEVE_MOVIES_SUCCESS](state, action) {
35-
// return {
36-
// ...state,
37-
// results: action.payload.response,
38-
// };
39-
// },
40-
// };
41-
4211
function movies(state = initialState, action) {
4312
switch (action.type) {
4413
case ActionTypes.RETRIEVE_MOVIES_START:
@@ -55,10 +24,6 @@ function movies(state = initialState, action) {
5524
isFetching: false,
5625
items: action.payload
5726
})
58-
case ActionTypes.SET_RESULTS:
59-
return Object.assign({}, state, {
60-
results: action.payload,
61-
})
6227
default:
6328
return state
6429
}

src/style/main.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ input[type=text]:focus {
6161

6262
.list {
6363
width: 100%;
64-
margin-top: 2em;
64+
margin: 2rem 0; }
65+
66+
.list-item {
67+
width: 100%;
6568
background: #fff;
6669
min-height: 500px;
6770
border-radius: 5px;
68-
margin-bottom: 2em; }
71+
padding: 0.5rem 0; }
6972

7073
@media only screen and (min-width: 992px) {
7174
.container {

src/style/main.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ input[type=text]:focus {
7474

7575
.list {
7676
width: 100%;
77-
margin-top: 2em;
77+
margin: 2rem 0;
78+
}
79+
80+
.list-item {
81+
width: 100%;
7882
background: $white;
7983
min-height: 500px;
8084
border-radius: 5px;
81-
margin-bottom: 2em;
85+
padding: 0.5rem 0;
8286
}
8387

8488
@media only screen and (min-width: 992px) {

0 commit comments

Comments
 (0)