Browse Source

Clean up store

dev
David Ludwig 4 years ago
parent
commit
74ff3b5265
3 changed files with 18 additions and 8 deletions
  1. +16
    -6
      services/webui/src/app/store/actions.ts
  2. +1
    -1
      services/webui/src/app/store/mutations.ts
  3. +1
    -1
      services/webui/src/app/store/state.ts

+ 16
- 6
services/webui/src/app/store/actions.ts View File

@ -31,6 +31,7 @@ export enum Action {
AuthLogin = "AUTH_LOGIN", AuthLogin = "AUTH_LOGIN",
AuthForget = "AUHT_FORGET", AuthForget = "AUHT_FORGET",
AuthLoad = "AUTH_LOAD", AuthLoad = "AUTH_LOAD",
AuthVerify = "AUTH_VERIFY",
// Movies Methods // Movies Methods
ActiveMovieRequests = "ACTIVE_MOVIE_REQUESTS", ActiveMovieRequests = "ACTIVE_MOVIE_REQUESTS",
@ -45,6 +46,7 @@ export enum Action {
*/ */
export type ActionsTypes = { export type ActionsTypes = {
// RESTful Generics // RESTful Generics
// @TODO These shouldn't be actions as they pollute the logs
[Action.Fetch] : (payload: IGetPayload) => Promise<any>, [Action.Fetch] : (payload: IGetPayload) => Promise<any>,
[Action.Get] : (payload: IGetPayload) => Promise<any>, [Action.Get] : (payload: IGetPayload) => Promise<any>,
[Action.Post] : (payload: IPostPayload) => Promise<any>, [Action.Post] : (payload: IPostPayload) => Promise<any>,
@ -55,7 +57,8 @@ export type ActionsTypes = {
[Action.AuthRegister]: (payload: IRegisterPayload) => Promise<IFormErrors|null>, [Action.AuthRegister]: (payload: IRegisterPayload) => Promise<IFormErrors|null>,
[Action.AuthLogin] : (payload: ILoginPayload) => Promise<IFormErrors|null>, [Action.AuthLogin] : (payload: ILoginPayload) => Promise<IFormErrors|null>,
[Action.AuthForget] : () => void, [Action.AuthForget] : () => void,
[Action.AuthLoad] : () => boolean,
[Action.AuthLoad] : () => void,
[Action.AuthVerify] : () => void,
// Movie Methods // Movie Methods
[Action.ActiveMovieRequests]: () => Promise<[number, IApiDataResponse<IMovie[]>]>, [Action.ActiveMovieRequests]: () => Promise<[number, IApiDataResponse<IMovie[]>]>,
@ -184,7 +187,7 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes
async [Action.AuthLogin]({commit, dispatch}, {email, password, remember = false}) { async [Action.AuthLogin]({commit, dispatch}, {email, password, remember = false}) {
try { try {
let [status, response] = await dispatch(Action.Post, { let [status, response] = await dispatch(Action.Post, {
path: `/auth/login?use_cookies=${navigator.cookieEnabled}`,
path: "/auth/login",
useAuth: false, useAuth: false,
body: {email, password}}); body: {email, password}});
if (status !== 200) { if (status !== 200) {
@ -213,18 +216,25 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes
/** /**
* Load the user from local storage * Load the user from local storage
*/ */
[Action.AuthLoad]({getters, commit, dispatch}) {
async [Action.AuthLoad]({getters, commit, dispatch}) {
let token = getters.storedToken; let token = getters.storedToken;
if (!token) { if (!token) {
return false;
return;
} }
try { try {
commit(Mutation.UserLoad, token); commit(Mutation.UserLoad, token);
await dispatch(Action.AuthVerify, undefined);
} catch(e) { } catch(e) {
dispatch(Action.AuthForget, undefined); dispatch(Action.AuthForget, undefined);
return false;
} }
return true;
},
/**
* Verify the current authentication session
*/
async [Action.AuthVerify]({getters}) {
let token = getters.storedToken;
// TODO
}, },
// Movies -------------------------------------------------------------------------------------- // Movies --------------------------------------------------------------------------------------


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

@ -73,7 +73,7 @@ export const mutations: MutationsTypes & MutationTree<IState> = {
name : user.name, name : user.name,
isAdmin: user.isAdmin, isAdmin: user.isAdmin,
token : token token : token
}
};
} catch(e) { } catch(e) {
return false; return false;
} }


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

@ -6,7 +6,7 @@ import Modal from "../components/modals";
* The state definition * The state definition
*/ */
export interface IState { export interface IState {
movies : {
movies: {
[tmdbId: string]: { [tmdbId: string]: {
refCount: number, refCount: number,
movie: IMovie movie: IMovie


Loading…
Cancel
Save