87 lines
1.7 KiB
JavaScript
87 lines
1.7 KiB
JavaScript
import { configureAxios, request } from '../requests'
|
|
|
|
import { addAlertOk } from './alerts'
|
|
|
|
export function updateLastMovieFetchUrl(url) {
|
|
return {
|
|
type: 'UPDATE_LAST_MOVIE_FETCH_URL',
|
|
payload: {
|
|
url: url,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function selectMovie(imdbId) {
|
|
return {
|
|
type: 'SELECT_MOVIE',
|
|
imdbId
|
|
}
|
|
}
|
|
|
|
export function getMovieExploreOptions() {
|
|
return request(
|
|
'MOVIE_GET_EXPLORE_OPTIONS',
|
|
configureAxios().get('/movies/explore/options')
|
|
)
|
|
}
|
|
|
|
export function getMovieDetails(imdbId) {
|
|
return request(
|
|
'MOVIE_GET_DETAILS',
|
|
configureAxios().post(`/movies/${imdbId}/refresh`)
|
|
)
|
|
}
|
|
|
|
export function deleteMovie(imdbId, lastFetchUrl) {
|
|
return request(
|
|
'MOVIE_DELETE',
|
|
configureAxios().delete(`/movies/${imdbId}`),
|
|
[
|
|
fetchMovies(lastFetchUrl),
|
|
addAlertOk("Movie deleted"),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function addMovieToWishlist(imdbId) {
|
|
return request(
|
|
'MOVIE_ADD_TO_WISHLIST',
|
|
configureAxios().post(`/wishlist/movies/${imdbId}`),
|
|
[
|
|
addAlertOk("Movie added to the wishlist"),
|
|
updateMovieWishlistStore(imdbId, true),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function deleteMovieFromWishlist(imdbId) {
|
|
return request(
|
|
'MOVIE_DELETE_FROM_WISHLIST',
|
|
configureAxios().delete(`/wishlist/movies/${imdbId}`),
|
|
[
|
|
addAlertOk("Movie deleted from the wishlist"),
|
|
updateMovieWishlistStore(imdbId, false),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function updateMovieWishlistStore(imdbId, wishlisted) {
|
|
return {
|
|
type: 'MOVIE_UPDATE_STORE_WISHLIST',
|
|
payload: {
|
|
imdbId,
|
|
wishlisted,
|
|
}
|
|
}
|
|
}
|
|
|
|
export function fetchMovies(url) {
|
|
return request(
|
|
'MOVIE_LIST_FETCH',
|
|
configureAxios().get(url),
|
|
[
|
|
updateLastMovieFetchUrl(url),
|
|
]
|
|
)
|
|
}
|