|
|
@ -1,4 +1,4 @@ |
|
|
|
import Modal from "@app/components/modals"; |
|
|
|
import { IMovie } from "@autoplex-api/request/dist/typings"; |
|
|
|
import jwtDecode from "jwt-decode"; |
|
|
|
import { MutationTree } from "vuex"; |
|
|
|
import { IState } from "./state"; |
|
|
@ -14,6 +14,8 @@ export enum Mutation { |
|
|
|
UserLoad = "USER_LOAD", |
|
|
|
UserStore = "USER_STORE", |
|
|
|
|
|
|
|
FreeMovies = "FREE_MOVIES", |
|
|
|
StoreMovies = "STORE_MOVIES", |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -24,6 +26,10 @@ export type MutationsTypes<S = IState> = { |
|
|
|
[Mutation.UserLoad] : (state: S, token: string) => boolean, |
|
|
|
[Mutation.UserStore] : (state: S, remember: boolean) => void, |
|
|
|
[Mutation.LockScroll]: (state: S, lock: boolean) => void, |
|
|
|
|
|
|
|
// Movie Store
|
|
|
|
[Mutation.FreeMovies]: (state: S, movies: IMovie[]) => void, |
|
|
|
[Mutation.StoreMovies]: (state: S, movies: IMovie[]) => void |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -88,5 +94,38 @@ export const mutations: MutationsTypes & MutationTree<IState> = { |
|
|
|
} else { |
|
|
|
sessionStorage.setItem("jwt", state.user.token); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// Movie Store ---------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** |
|
|
|
* Free the cached movies from the store |
|
|
|
*/ |
|
|
|
[Mutation.FreeMovies](state, movies: IMovie[]) { |
|
|
|
for (let movie of movies) { |
|
|
|
if (!(movie.tmdbId in state.movies)) { |
|
|
|
console.warn("Attempted to free a movie not stored in the state!"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
state.movies[movie.tmdbId].refCount--; |
|
|
|
if (state.movies[movie.tmdbId].refCount <= 0) { |
|
|
|
delete state.movies[movie.tmdbId]; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Insert movie references in the store for updates |
|
|
|
*/ |
|
|
|
[Mutation.StoreMovies](state, movies: IMovie[]) { |
|
|
|
for (let movie of movies) { |
|
|
|
if (!(movie.tmdbId in state.movies)) { |
|
|
|
state.movies[movie.tmdbId] = { |
|
|
|
refCount: 0, |
|
|
|
movie |
|
|
|
}; |
|
|
|
} |
|
|
|
state.movies[movie.tmdbId].refCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |