Browse Source

Add movie ticket caching to state. Include actions and mutations as well

dev
David Ludwig 4 years ago
parent
commit
f252dbd7d8
3 changed files with 50 additions and 6 deletions
  1. +27
    -2
      services/webui/src/app/store/actions.ts
  2. +21
    -4
      services/webui/src/app/store/mutations.ts
  3. +2
    -0
      services/webui/src/app/store/state.ts

+ 27
- 2
services/webui/src/app/store/actions.ts View File

@ -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);
}
};

+ 21
- 4
services/webui/src/app/store/mutations.ts View File

@ -14,8 +14,9 @@ export enum Mutation {
UserLoad = "USER_LOAD",
UserStore = "USER_STORE",
FreeMovies = "FREE_MOVIES",
StoreMovies = "STORE_MOVIES",
FreeMovies = "FREE_MOVIES",
StoreMovies = "STORE_MOVIES",
UpdateMovieTickets = "UPDATE_MOVIE_TICKETS"
}
/**
@ -28,8 +29,9 @@ export type MutationsTypes<S = IState> = {
[Mutation.LockScroll]: (state: S, lock: boolean) => void,
// Movie Store
[Mutation.FreeMovies]: (state: S, movies: IMovie[]) => void,
[Mutation.StoreMovies]: (state: S, movies: IMovie[]) => void
[Mutation.FreeMovies] : (state: S, movies: IMovie[]) => void,
[Mutation.StoreMovies] : (state: S, movies: IMovie[]) => void,
[Mutation.UpdateMovieTickets]: (state: S) => void
}
/**
@ -127,5 +129,20 @@ export const mutations: MutationsTypes & MutationTree<IState> = {
}
state.movies[movie.tmdbId].refCount++;
}
},
/**
* Update the cached movie tickets in the store
*/
[Mutation.UpdateMovieTickets](state) {
let tickets: { [ticketId: number]: string } = {};
for (let tmdbId of Object.keys(state.movies)) {
let ticketId = state.movies[tmdbId].movie.ticketId;
let plexLink = state.movies[tmdbId].movie.plexLink;
if (ticketId !== null && plexLink === null) {
tickets[ticketId] = tmdbId;
}
}
state.movieTickets = tickets;
}
}

+ 2
- 0
services/webui/src/app/store/state.ts View File

@ -12,6 +12,7 @@ export interface IState {
movie: IMovie
}
},
movieTickets: { [ticketId: number]: string },
user : IUser | null,
modalName : Modal | null,
modalVisible: boolean
@ -22,6 +23,7 @@ export interface IState {
*/
export const state: IState = {
movies: {},
movieTickets: {},
user: null,
modalName: null,
modalVisible: false,


Loading…
Cancel
Save