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


Loading…
Cancel
Save