File size: 1,127 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import MovieActionTypes from "./movie-types";
const INITIAL_STATE = {
isFetching: true,
isAdditionalFetching: true,
movieItems: [],
movieGridItems: [],
movieCast: [],
movieVideos: ""
};
const movieReducer = (state = INITIAL_STATE, action) => {
const { type, payload } = action;
switch (type) {
case MovieActionTypes.SET_MOVIE_DATA: {
return { ...state, movieItems: payload };
}
case MovieActionTypes.SET_MOVIE_GRID_DATA: {
return { ...state, movieGridItems: payload };
}
case MovieActionTypes.SET_MOVIE_DATA_SUCCESS: {
return { ...state, isFetching: false };
}
case MovieActionTypes.SET_MOVIE_ADDITIONAL_DATA_SUCCESS: {
return { ...state, isAdditionalFetching: false };
}
case MovieActionTypes.SET_MOVIE_ADDITIONAL_DATA: {
return {
...state,
movieCast: payload.credits.cast,
movieVideos: payload.videos.results.length
? payload.videos.results[0].key
: "no_trailer_found"
};
}
default:
return state;
}
};
export default movieReducer;
|