implemented redux for state management
This commit is contained in:
84
src/store/actions/index.js
Normal file
84
src/store/actions/index.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import axios from '../../axios-movies';
|
||||
|
||||
export const FETCH_TRENDING = 'FETCH_TRENDING';
|
||||
export const FETCH_NETFLIX_ORIGINALS = 'FETCH_NETFLIX_ORIGINALS';
|
||||
export const FETCH_TOP_RATED = 'FETCH_TOP_RATED';
|
||||
export const FETCH_ACTION_MOVIES = 'FETCH_ACTION_MOVIES';
|
||||
export const FETCH_COMEDY_MOVIES = 'FETCH_COMEDY_MOVIES';
|
||||
export const FETCH_HORROR_MOVIES = 'FETCH_HORROR_MOVIES';
|
||||
export const FETCH_ROMANCE_MOVIES = 'FETCH_ROMANCE_MOVIES';
|
||||
export const FETCH_DOCUMENTARIES = 'FETCH_DOCUMENTARIES';
|
||||
|
||||
const API_KEY = '224ce27b38a3805ecf6f6c36eb3ba9d0';
|
||||
|
||||
export function fetchTrending() {
|
||||
const request = axios.get(`/trending/all/week?api_key=${API_KEY}&language=en-US`);
|
||||
|
||||
return {
|
||||
type: FETCH_TRENDING,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchNetflixOriginals() {
|
||||
const request = axios.get(`/discover/tv?api_key=${API_KEY}&with_networks=213`);
|
||||
|
||||
return {
|
||||
type: FETCH_NETFLIX_ORIGINALS,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchTopRated() {
|
||||
const request = axios.get(`/movie/top_rated?api_key=${API_KEY}&language=en-US`)
|
||||
|
||||
return {
|
||||
type: FETCH_TOP_RATED,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchActionMovies() {
|
||||
const request = axios.get(`/discover/movie?api_key=${API_KEY}&with_genres=28`)
|
||||
|
||||
return {
|
||||
type: FETCH_ACTION_MOVIES,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchComedyMovies() {
|
||||
const request = axios.get(`/discover/movie?api_key=${API_KEY}&with_genres=35`)
|
||||
|
||||
return {
|
||||
type: FETCH_COMEDY_MOVIES,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchHorrorMovies() {
|
||||
const request = axios.get(`/discover/movie?api_key=${API_KEY}&with_genres=27`)
|
||||
|
||||
return {
|
||||
type: FETCH_HORROR_MOVIES,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchRomanceMovies() {
|
||||
const request = axios.get(`/discover/movie?api_key=${API_KEY}&with_genres=10749`)
|
||||
|
||||
return {
|
||||
type: FETCH_ROMANCE_MOVIES,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchDocumentaries() {
|
||||
const request = axios.get(`/discover/movie?api_key=${API_KEY}&with_genres=99`)
|
||||
|
||||
return {
|
||||
type: FETCH_DOCUMENTARIES,
|
||||
payload: request
|
||||
}
|
||||
}
|
||||
23
src/store/reducers/index.js
Normal file
23
src/store/reducers/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import TrendingReducer from './reducerTrending';
|
||||
import NetflixOriginalsReducer from './reducerNetflixOriginals';
|
||||
import TopRatedReducer from './reducerTopRated';
|
||||
import ActionMoviesReducer from './reducerActionMovies';
|
||||
import ComedyMoviesReducer from './reducerComedyMovies';
|
||||
import HorrorMoviesReducer from './reducerHorrorMovies';
|
||||
import RomanceMoviesReducer from './reducerRomanceMovies';
|
||||
import DocumentaryReducer from './reducerDocumentary';
|
||||
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
trending: TrendingReducer,
|
||||
netflixOriginals: NetflixOriginalsReducer,
|
||||
topRated: TopRatedReducer,
|
||||
action: ActionMoviesReducer,
|
||||
comedy: ComedyMoviesReducer,
|
||||
horror: HorrorMoviesReducer,
|
||||
romance: RomanceMoviesReducer,
|
||||
documentary: DocumentaryReducer
|
||||
});
|
||||
|
||||
export default rootReducer;
|
||||
11
src/store/reducers/reducerActionMovies.js
Normal file
11
src/store/reducers/reducerActionMovies.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_ACTION_MOVIES } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_ACTION_MOVIES:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerComedyMovies.js
Normal file
11
src/store/reducers/reducerComedyMovies.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_COMEDY_MOVIES } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_COMEDY_MOVIES:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerDocumentary.js
Normal file
11
src/store/reducers/reducerDocumentary.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_DOCUMENTARIES } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_DOCUMENTARIES:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerHorrorMovies.js
Normal file
11
src/store/reducers/reducerHorrorMovies.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_HORROR_MOVIES } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_HORROR_MOVIES:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerNetflixOriginals.js
Normal file
11
src/store/reducers/reducerNetflixOriginals.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_NETFLIX_ORIGINALS } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_NETFLIX_ORIGINALS:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerRomanceMovies.js
Normal file
11
src/store/reducers/reducerRomanceMovies.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_ROMANCE_MOVIES } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_ROMANCE_MOVIES:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerTopRated.js
Normal file
11
src/store/reducers/reducerTopRated.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_TOP_RATED } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_TOP_RATED:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
11
src/store/reducers/reducerTrending.js
Normal file
11
src/store/reducers/reducerTrending.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_TRENDING } from '../actions/index';
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_TRENDING:
|
||||
const data = action.payload.data.results;
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user