refactored Header component
This commit is contained in:
@@ -1,98 +1,117 @@
|
||||
import axios from '../../axios-movies';
|
||||
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';
|
||||
export const FETCH_HEADER_MOVIE = 'FETCH_HEADER_MOVIE'
|
||||
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'
|
||||
|
||||
export function fetchTrending() {
|
||||
export const fetchHeaderMovie = () => {
|
||||
const movieId = 63351
|
||||
return async (dispatch) => {
|
||||
try {
|
||||
const request = await axios.get(
|
||||
`tv/${movieId}?api_key=${process.env.API_KEY}`
|
||||
)
|
||||
|
||||
dispatch({ type: FETCH_HEADER_MOVIE, payload: request })
|
||||
} catch (error) {
|
||||
console.log('error', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchNetflixOriginals = () => {
|
||||
return async (dispatch) => {
|
||||
try {
|
||||
const request = await axios.get(
|
||||
`/discover/tv?api_key=${process.env.API_KEY}&with_networks=213`
|
||||
)
|
||||
|
||||
dispatch({ type: FETCH_NETFLIX_ORIGINALS, payload: request })
|
||||
} catch (error) {
|
||||
console.log('error', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchTrending = () => {
|
||||
const request = axios.get(
|
||||
`/trending/all/week?api_key=${process.env.API_KEY}&language=en-US`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_TRENDING,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchNetflixOriginals() {
|
||||
const request = axios.get(
|
||||
`/discover/tv?api_key=${process.env.API_KEY}&with_networks=213`
|
||||
);
|
||||
|
||||
return {
|
||||
type: FETCH_NETFLIX_ORIGINALS,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchTopRated() {
|
||||
export const fetchTopRated = () => {
|
||||
const request = axios.get(
|
||||
`/movie/top_rated?api_key=${process.env.API_KEY}&language=en-US`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_TOP_RATED,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchActionMovies() {
|
||||
export const fetchActionMovies = () => {
|
||||
const request = axios.get(
|
||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=28`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_ACTION_MOVIES,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchComedyMovies() {
|
||||
export const fetchComedyMovies = () => {
|
||||
const request = axios.get(
|
||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=35`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_COMEDY_MOVIES,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchHorrorMovies() {
|
||||
export const fetchHorrorMovies = () => {
|
||||
const request = axios.get(
|
||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=27`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_HORROR_MOVIES,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchRomanceMovies() {
|
||||
export const fetchRomanceMovies = () => {
|
||||
const request = axios.get(
|
||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=10749`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_ROMANCE_MOVIES,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchDocumentaries() {
|
||||
export const fetchDocumentaries = () => {
|
||||
const request = axios.get(
|
||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=99`
|
||||
);
|
||||
)
|
||||
|
||||
return {
|
||||
type: FETCH_DOCUMENTARIES,
|
||||
payload: request,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
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';
|
||||
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'
|
||||
import HeaderMovieReducer from './reducerHeaderMovie'
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
trending: TrendingReducer,
|
||||
@@ -17,6 +18,7 @@ const rootReducer = combineReducers({
|
||||
horror: HorrorMoviesReducer,
|
||||
romance: RomanceMoviesReducer,
|
||||
documentary: DocumentaryReducer,
|
||||
});
|
||||
headerMovie: HeaderMovieReducer,
|
||||
})
|
||||
|
||||
export default rootReducer;
|
||||
export default rootReducer
|
||||
|
||||
11
src/store/reducers/reducerHeaderMovie.js
Normal file
11
src/store/reducers/reducerHeaderMovie.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { FETCH_HEADER_MOVIE } from '../actions/index'
|
||||
|
||||
export default function (state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_HEADER_MOVIE:
|
||||
const data = action.payload.data
|
||||
return { ...state, ...data }
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { FETCH_NETFLIX_ORIGINALS } from '../actions/index';
|
||||
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 };
|
||||
const data = action.payload.data.results
|
||||
return { ...state, data }
|
||||
default:
|
||||
return state;
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user