|
|
@ -38,7 +38,11 @@ export enum Action { |
|
|
|
MovieDetails = "MOVIE_DETAILS", |
|
|
|
CancelMovieRequest = "CANCEL_MOVIE_REQUEST", |
|
|
|
CreateMovieRequest = "CREATE_MOVIE_REQUEST", |
|
|
|
SearchMovies = "SEARCH_MOVIES" |
|
|
|
SearchMovies = "SEARCH_MOVIES", |
|
|
|
|
|
|
|
// Movie Store
|
|
|
|
UpdateMovies = "UPDATE_MOVIES", |
|
|
|
UpdateMovieTickets = "UPDATE_MOVIE_TICKETS" |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -65,7 +69,10 @@ export type ActionsTypes = { |
|
|
|
[Action.MovieDetails] : (tmdbId: number | string) => Promise<[number, IApiDataResponse<IMovieDetails>]>, |
|
|
|
[Action.SearchMovies] : (query: string) => Promise<[number, IPaginatedResponse<IMovie>]>, |
|
|
|
[Action.CancelMovieRequest] : (ticketId: number) => Promise<[number, IApiResponse]>, |
|
|
|
[Action.CreateMovieRequest] : (tmdbId: number | string) => Promise<[number, IApiDataResponse<{ ticketId: number }>]> |
|
|
|
[Action.CreateMovieRequest] : (tmdbId: number | string) => Promise<[number, IApiDataResponse<{ ticketId: number }>]>, |
|
|
|
|
|
|
|
// Movie Store
|
|
|
|
[Action.UpdateMovies]: (movies: { newValue: IMovie[], oldValue: IMovie[] }) => void |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -282,5 +289,23 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes |
|
|
|
return await dispatch(Action.Post, { |
|
|
|
path: `/api/movie/request/create/${tmdbId}` |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// Movie Store ---------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** |
|
|
|
* Update the cached movies in the store |
|
|
|
*/ |
|
|
|
[Action.UpdateMovies]({commit, dispatch}, {newValue, oldValue}) { |
|
|
|
if (newValue.length == 0 && oldValue.length == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (newValue.length > 0) { |
|
|
|
commit(Mutation.StoreMovies, newValue); |
|
|
|
} |
|
|
|
if (oldValue.length > 0) { |
|
|
|
commit(Mutation.FreeMovies, oldValue); |
|
|
|
} |
|
|
|
commit(Mutation.UpdateMovieTickets, undefined); |
|
|
|
} |
|
|
|
}; |