refactored action creators
This commit is contained in:
@@ -11,6 +11,12 @@ const MainContent = ({ selectMovieHandler }) => {
|
|||||||
const headerMovie = useSelector((state) => state.headerMovie)
|
const headerMovie = useSelector((state) => state.headerMovie)
|
||||||
const netflixOriginals = useSelector((state) => state.netflixOriginals)
|
const netflixOriginals = useSelector((state) => state.netflixOriginals)
|
||||||
const trending = useSelector((state) => state.trending)
|
const trending = useSelector((state) => state.trending)
|
||||||
|
const topRated = useSelector((state) => state.topRated)
|
||||||
|
const actionMovies = useSelector((state) => state.action)
|
||||||
|
const comedyMovies= useSelector((state) => state.comedy)
|
||||||
|
const horrorMovies = useSelector((state) => state.horror)
|
||||||
|
const romanceMovies = useSelector((state) => state.romance)
|
||||||
|
const documentaries = useSelector((state) => state.documentary)
|
||||||
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
@@ -18,6 +24,12 @@ const MainContent = ({ selectMovieHandler }) => {
|
|||||||
dispatch(movieActions.fetchHeaderMovie())
|
dispatch(movieActions.fetchHeaderMovie())
|
||||||
dispatch(movieActions.fetchNetflixOriginals())
|
dispatch(movieActions.fetchNetflixOriginals())
|
||||||
dispatch(movieActions.fetchTrending())
|
dispatch(movieActions.fetchTrending())
|
||||||
|
dispatch(movieActions.fetchTopRated())
|
||||||
|
dispatch(movieActions.fetchActionMovies())
|
||||||
|
dispatch(movieActions.fetchComedyMovies())
|
||||||
|
dispatch(movieActions.fetchHorrorMovies())
|
||||||
|
dispatch(movieActions.fetchRomanceMovies())
|
||||||
|
dispatch(movieActions.fetchDocumentaries())
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -35,6 +47,36 @@ const MainContent = ({ selectMovieHandler }) => {
|
|||||||
selectMovieHandler={selectMovieHandler}
|
selectMovieHandler={selectMovieHandler}
|
||||||
movies={trending.data}
|
movies={trending.data}
|
||||||
/>
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Top Rated'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={topRated.data}
|
||||||
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Action Movies'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={actionMovies.data}
|
||||||
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Comedy'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={comedyMovies.data}
|
||||||
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Horror Movies'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={horrorMovies.data}
|
||||||
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Romance'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={romanceMovies.data}
|
||||||
|
/>
|
||||||
|
<DisplayMovieRow
|
||||||
|
title='Documentaries'
|
||||||
|
selectMovieHandler={selectMovieHandler}
|
||||||
|
movies={documentaries.data}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,67 +51,69 @@ export const fetchTrending = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetchTopRated = () => {
|
export const fetchTopRated = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/movie/top_rated?api_key=${process.env.API_KEY}&language=en-US`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/movie/top_rated?api_key=${process.env.API_KEY}&language=en-US`
|
||||||
return {
|
)
|
||||||
type: FETCH_TOP_RATED,
|
dispatch({ type: FETCH_TOP_RATED, payload: request })
|
||||||
payload: request,
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchActionMovies = () => {
|
export const fetchActionMovies = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=28`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=28`
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
dispatch({ type: FETCH_ACTION_MOVIES, payload: request })
|
||||||
type: FETCH_ACTION_MOVIES,
|
} catch (error) {}
|
||||||
payload: request,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchComedyMovies = () => {
|
export const fetchComedyMovies = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=35`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=35`
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
dispatch({ type: FETCH_COMEDY_MOVIES, payload: request })
|
||||||
type: FETCH_COMEDY_MOVIES,
|
} catch (error) {}
|
||||||
payload: request,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchHorrorMovies = () => {
|
export const fetchHorrorMovies = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=27`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=27`
|
||||||
return {
|
)
|
||||||
type: FETCH_HORROR_MOVIES,
|
dispatch({ type: FETCH_HORROR_MOVIES, payload: request })
|
||||||
payload: request,
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchRomanceMovies = () => {
|
export const fetchRomanceMovies = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=10749`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=10749`
|
||||||
return {
|
)
|
||||||
type: FETCH_ROMANCE_MOVIES,
|
dispatch({ type: FETCH_ROMANCE_MOVIES, payload: request })
|
||||||
payload: request,
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchDocumentaries = () => {
|
export const fetchDocumentaries = () => {
|
||||||
const request = axios.get(
|
return async (dispatch) => {
|
||||||
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=99`
|
try {
|
||||||
)
|
const request = await axios.get(
|
||||||
|
`/discover/movie?api_key=${process.env.API_KEY}&with_genres=99`
|
||||||
return {
|
)
|
||||||
type: FETCH_DOCUMENTARIES,
|
dispatch({ type: FETCH_DOCUMENTARIES, payload: request })
|
||||||
payload: request,
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user