This repository was archived by the owner on Sep 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +61
-77
lines changed
Expand file tree Collapse file tree 11 files changed +61
-77
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 11import fetch from 'isomorphic-fetch' ;
22import ActionTypes from '../constants' ;
33
4- export const setResults = ( result ) => ( {
5- type : ActionTypes . SET_RESULTS ,
6- payload : {
7- result
8- } ,
9- } ) ;
10-
114function retrieveMoviesStart ( ) {
125 return {
136 type : ActionTypes . RETRIEVE_MOVIES_START ,
@@ -17,24 +10,21 @@ function retrieveMoviesStart() {
1710function retrieveMoviesError ( error ) {
1811 return {
1912 type : ActionTypes . RETRIEVE_MOVIES_ERROR ,
20- payload : {
21- error
22- }
13+ payload : error
2314 } ;
2415}
2516
2617function retrieveMoviesSuccess ( response ) {
2718 return {
2819 type : ActionTypes . RETRIEVE_MOVIES_SUCCESS ,
29- payload :
30- response
20+ payload : response
3121 } ;
3222}
3323
3424export 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 } ) ;
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 11export 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} ;
Original file line number Diff line number Diff line change 11import React , { Component , PropTypes } from 'react'
22import { connect } from 'react-redux'
3- import List from '../components /List'
3+ import List from './List'
44import InputSet from './InputSet' ;
55import * as MoviesAction from '../actions'
66import { 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 }
Original file line number Diff line number Diff 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
5247InputSet . propTypes = {
5348 movies : PropTypes . object ,
54- retrieveMovies : PropTypes . func ,
55- setResults : PropTypes . func ,
49+ retrieveMovies : PropTypes . func
5650}
5751
5852function mapStateToProps ( state ) {
Original file line number Diff line number Diff line change 11import React , { PropTypes , Component } from 'react' ;
22import { connect } from 'react-redux' ;
33import '../style/main.css' ;
4+ import ListItem from '../components/ListItem' ;
5+ import createList from '../utils' ;
46
57class 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 }
Original file line number Diff line number Diff line change 1- // import { combineReducers } from 'redux'
2- import ActionTypes from '../constants'
31import { combineReducers } from 'redux' ;
42import { routerStateReducer } from 'redux-router' ;
3+ import ActionTypes from '../constants'
54
65const 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-
4211function 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 }
Original file line number Diff line number Diff 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 : 2 em ; }
71+ padding : 0.5 rem 0 ; }
6972
7073@media only screen and (min-width : 992px ) {
7174 .container {
Original file line number Diff line number Diff 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 : 2 em ;
85+ padding : 0.5 rem 0 ;
8286}
8387
8488@media only screen and (min-width : 992px ) {
You can’t perform that action at this time.
0 commit comments