250 lines
4.5 KiB
JavaScript
250 lines
4.5 KiB
JavaScript
import { configureAxios, request } from '../requests'
|
|
|
|
// ======================
|
|
// Alerts
|
|
// ======================
|
|
|
|
export function addAlertError(message) {
|
|
return {
|
|
type: 'ADD_ALERT_ERROR',
|
|
payload: {
|
|
message,
|
|
}
|
|
}
|
|
}
|
|
|
|
export function addAlertOk(message) {
|
|
return {
|
|
type: 'ADD_ALERT_OK',
|
|
payload: {
|
|
message,
|
|
}
|
|
}
|
|
}
|
|
|
|
export function dismissAlert() {
|
|
return {
|
|
type: 'DISMISS_ALERT',
|
|
}
|
|
}
|
|
|
|
// ======================
|
|
// Users
|
|
// ======================
|
|
|
|
export function userLogout() {
|
|
return {
|
|
type: 'USER_LOGOUT',
|
|
}
|
|
}
|
|
|
|
export function isUserLoggedIn() {
|
|
return {
|
|
type: 'IS_USER_LOGGED_IN',
|
|
}
|
|
}
|
|
|
|
export function loginUser(username, password) {
|
|
return request(
|
|
'USER_LOGIN',
|
|
configureAxios().post(
|
|
'/users/login',
|
|
{
|
|
username: username,
|
|
password: password,
|
|
},
|
|
),
|
|
)
|
|
}
|
|
|
|
export function updateUser(config) {
|
|
return request(
|
|
'USER_UPDATE',
|
|
configureAxios().post('/users/edit', config),
|
|
[
|
|
addAlertOk("User updated"),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function userSignUp(config) {
|
|
return request(
|
|
'USER_SIGNUP',
|
|
configureAxios().post('/users/signup', config)
|
|
)
|
|
}
|
|
|
|
export function getUserInfos() {
|
|
return request(
|
|
'GET_USER',
|
|
configureAxios().get('/users/details')
|
|
)
|
|
}
|
|
|
|
// ======================
|
|
// Movies
|
|
// ======================
|
|
|
|
export function selectMovie(imdbId) {
|
|
return {
|
|
type: 'SELECT_MOVIE',
|
|
imdbId
|
|
}
|
|
}
|
|
|
|
export function deleteMovieFromStore(imdbId) {
|
|
return {
|
|
type: 'DELETE_MOVIE',
|
|
imdbId
|
|
}
|
|
}
|
|
|
|
export function searchMovies(search) {
|
|
return request(
|
|
'SEARCH_MOVIES',
|
|
configureAxios().post('/movies/search', search)
|
|
)
|
|
}
|
|
|
|
export function getMovieDetails(imdbId) {
|
|
return request(
|
|
'MOVIE_GET_DETAILS',
|
|
configureAxios().post(`/movies/${imdbId}/refresh`)
|
|
)
|
|
}
|
|
|
|
export function deleteMovie(imdbId) {
|
|
return request(
|
|
'MOVIE_DELETE',
|
|
configureAxios().delete(`/movies/${imdbId}`),
|
|
[
|
|
addAlertOk("Movie deleted"),
|
|
deleteMovieFromStore(imdbId),
|
|
],
|
|
)
|
|
}
|
|
|
|
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)
|
|
)
|
|
}
|
|
|
|
// ======================
|
|
// Shows
|
|
// ======================
|
|
|
|
export function fetchShows(url) {
|
|
return request(
|
|
'SHOW_LIST_FETCH',
|
|
configureAxios().get(url)
|
|
)
|
|
}
|
|
|
|
export function searchShows(search) {
|
|
return request(
|
|
'SEARCH_SHOWS',
|
|
configureAxios().post('/shows/search', search)
|
|
)
|
|
}
|
|
|
|
export function fetchShowDetails(imdbId) {
|
|
return request(
|
|
'SHOW_FETCH_DETAILS',
|
|
configureAxios().get(`/shows/${imdbId}`)
|
|
)
|
|
}
|
|
|
|
export function addShowToWishlist(imdbId, season = null, episode = null) {
|
|
return request(
|
|
'SHOW_ADD_TO_WISHLIST',
|
|
configureAxios().post(`/wishlist/shows/${imdbId}`, {
|
|
season: season,
|
|
episode: episode,
|
|
}),
|
|
[
|
|
addAlertOk("Show added to the wishlist"),
|
|
updateShowWishlistStore(imdbId, true, season, episode),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function deleteShowFromWishlist(imdbId) {
|
|
return request(
|
|
'SHOW_DELETE_FROM_WISHLIST',
|
|
configureAxios().delete(`/wishlist/shows/${imdbId}`),
|
|
[
|
|
addAlertOk("Show deleted from the wishlist"),
|
|
updateShowWishlistStore(imdbId, false),
|
|
],
|
|
)
|
|
}
|
|
|
|
export function updateShowWishlistStore(imdbId, wishlisted, season = null, episode = null) {
|
|
return {
|
|
type: 'SHOW_UPDATE_STORE_WISHLIST',
|
|
payload: {
|
|
wishlisted: wishlisted,
|
|
imdbId,
|
|
season,
|
|
episode,
|
|
}
|
|
}
|
|
}
|
|
|
|
export function selectShow(imdbId) {
|
|
return {
|
|
type: 'SELECT_SHOW',
|
|
imdbId
|
|
}
|
|
}
|
|
|
|
// ======================
|
|
// AddTorrent
|
|
// ======================
|
|
|
|
export function addTorrent(url) {
|
|
return request(
|
|
'ADD_TORRENT',
|
|
configureAxios().post('/torrents', {
|
|
url: url,
|
|
}),
|
|
[
|
|
addAlertOk("Torrent added"),
|
|
],
|
|
)
|
|
}
|