From 6e736cafdf9c2612b9d69c09798869ef6f795d71 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Mon, 21 Jun 2021 13:00:40 -0500 Subject: [PATCH] Cancel/create movie requests trigger movie ticket updates --- services/webui/src/app/store/actions.ts | 13 +++++++--- services/webui/src/app/store/mutations.ts | 30 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/services/webui/src/app/store/actions.ts b/services/webui/src/app/store/actions.ts index 9c103a2..e67d3a1 100644 --- a/services/webui/src/app/store/actions.ts +++ b/services/webui/src/app/store/actions.ts @@ -276,7 +276,8 @@ export const actions: Actions]>(async resolve => { + let [status, response]: [number, IApiDataResponse<{ ticketId: number }>] = await dispatch(Action.Post, { + path: `/api/movie/request/create/${tmdbId}` + }); + commit(Mutation.StoreMovieTicket, { tmdbId, ticketId: response.result.ticketId }); + resolve([status, response]); }); }, diff --git a/services/webui/src/app/store/mutations.ts b/services/webui/src/app/store/mutations.ts index 1c33d4c..dc23845 100644 --- a/services/webui/src/app/store/mutations.ts +++ b/services/webui/src/app/store/mutations.ts @@ -16,6 +16,8 @@ export enum Mutation { FreeMovies = "FREE_MOVIES", StoreMovies = "STORE_MOVIES", + RemoveMovieTicket = "REMOVE_MOVIE_TICKET", + StoreMovieTicket = "STORE_MOVIE_TICKET", UpdateMovieTickets = "UPDATE_MOVIE_TICKETS" } @@ -31,6 +33,8 @@ export type MutationsTypes = { // Movie Store [Mutation.FreeMovies] : (state: S, movies: IMovie[]) => void, [Mutation.StoreMovies] : (state: S, movies: IMovie[]) => void, + [Mutation.RemoveMovieTicket] : (state: S, ticketId: number) => void, + [Mutation.StoreMovieTicket] : (state: S, payload: { tmdbId: string|number, ticketId: number}) => void, [Mutation.UpdateMovieTickets]: (state: S) => void } @@ -131,6 +135,32 @@ export const mutations: MutationsTypes & MutationTree = { } }, + /** + * Remove the given movie ticket + */ + [Mutation.RemoveMovieTicket](state, ticketId) { + let tmdbId = state.movieTickets[ticketId]; + if (tmdbId === undefined) { + return; + } + delete state.movieTickets[ticketId]; + state.movies[tmdbId].movie.ticketId = null; + state.movies[tmdbId].movie.progress = null; + }, + + /** + * Store a new ticket for the given movie + */ + [Mutation.StoreMovieTicket](state, {tmdbId, ticketId}) { + let entry = state.movies[tmdbId]; + if (entry === undefined) { + return; + } + entry.movie.ticketId = ticketId; + entry.movie.progress = 0; + state.movieTickets[ticketId] = tmdbId; + }, + /** * Update the cached movie tickets in the store */