From 46c4e6d3ebcd13722ce8878a350616e08a660856 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Fri, 17 Jun 2022 13:21:30 +0100 Subject: [PATCH] Simplify login logic Let LOGIN action handle displaying the modal if required. --- src/App.vue | 2 +- src/components/ChatBox.vue | 2 +- src/leaflet/control/LoginControl.ts | 2 +- src/store/actions.ts | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 05d40fa..8172da1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -194,7 +194,7 @@ export default defineComponent({ element: 'maps', state: false, }); - store.commit(MutationTypes.SHOW_UI_MODAL, 'login'); + store.dispatch(ActionTypes.LOGIN, null); notify('Login required'); showSplashError('Login required', true, 1); } else { diff --git a/src/components/ChatBox.vue b/src/components/ChatBox.vue index f2b62ed..9b3787f 100644 --- a/src/components/ChatBox.vue +++ b/src/components/ChatBox.vue @@ -99,7 +99,7 @@ } }, - login = () => store.commit(MutationTypes.SHOW_UI_MODAL, 'login'); + login = () => store.dispatch(ActionTypes.LOGIN, null); watch(chatBoxVisible, newValue => { if(newValue && sendingEnabled.value) { diff --git a/src/leaflet/control/LoginControl.ts b/src/leaflet/control/LoginControl.ts index fab0843..5a7dfbd 100644 --- a/src/leaflet/control/LoginControl.ts +++ b/src/leaflet/control/LoginControl.ts @@ -104,7 +104,7 @@ export class LoginControl extends Control { notify(logoutError.value); } } else { - this.store.commit(MutationTypes.SHOW_UI_MODAL, 'login'); + await this.store.dispatch(ActionTypes.LOGIN, null) } } } diff --git a/src/store/actions.ts b/src/store/actions.ts index 1b7ae55..6c302b4 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -202,7 +202,11 @@ export const actions: ActionTree & Actions = { }, async [ActionTypes.LOGIN]({state, commit}, data: any): Promise { - await state.currentMapProvider!.login(data); + if(data) { + await state.currentMapProvider!.login(data); + } else { + commit(MutationTypes.SHOW_UI_MODAL, 'login'); + } }, async [ActionTypes.LOGOUT]({state}): Promise {