From 1b9a3e4f1a351e35ab6e7345b86b06d6b4c461d4 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 8 Sep 2021 14:35:44 +0100 Subject: [PATCH] Cleanup configuration loading a bit - Move configuration hash clearing to RESET - Dispatch STOP_UPDATES and RESET actions from LOAD_CONFIGURATION action - Make exception handling simpler --- src/App.vue | 28 +++++++++------------------- src/store/actions.ts | 6 +++--- src/store/mutation-types.ts | 1 - src/store/mutations.ts | 7 +------ 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/App.vue b/src/App.vue index 50830b8..043eb7a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -74,8 +74,6 @@ export default defineComponent({ showSplash(!loadingAttempts.value); loading.value = true; - await store.dispatch(ActionTypes.STOP_UPDATES, undefined); - store.commit(MutationTypes.RESET, undefined); await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined); await store.dispatch(ActionTypes.START_UPDATES, undefined); @@ -89,23 +87,15 @@ export default defineComponent({ } }); } catch(e: any) { - //Request was aborted, probably because another server was selected before the request finished. Don't retry - if(e instanceof DOMException && e.name === 'AbortError') { - return; + // Don't retry if request was aborted or logging in is required + if(!(e instanceof DOMException && e.name === 'AbortError') && !loginRequired.value) { + const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`; + console.error(`${error}:`, e); + showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value); + + clearTimeout(loadingTimeout); + loadingTimeout = setTimeout(() => loadConfiguration(), 1000); } - - //Logging in is required - if(loginRequired.value) { - return; - } - - //Any other errors - const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`; - console.error(`${error}:`, e); - showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value); - - clearTimeout(loadingTimeout); - loadingTimeout = setTimeout(() => loadConfiguration(), 1000); } finally { loading.value = false; } @@ -212,7 +202,7 @@ export default defineComponent({ } else { store.commit(MutationTypes.HIDE_UI_MODAL, 'login'); } - }) + }); onMounted(() => loadConfiguration()); onBeforeUnmount(() => { diff --git a/src/store/actions.ts b/src/store/actions.ts index f7a9f88..89f2e57 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -85,9 +85,9 @@ export interface Actions { } export const actions: ActionTree & Actions = { - async [ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise { - //Clear any existing has to avoid triggering a second config load, after this load changes the hash - commit(MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH, undefined); + async [ActionTypes.LOAD_CONFIGURATION]({commit, state, dispatch}): Promise { + await dispatch(ActionTypes.STOP_UPDATES, undefined); + commit(MutationTypes.RESET, undefined); if(!state.currentServer) { console.warn('No current server'); diff --git a/src/store/mutation-types.ts b/src/store/mutation-types.ts index 19abcd4..764c47e 100644 --- a/src/store/mutation-types.ts +++ b/src/store/mutation-types.ts @@ -19,7 +19,6 @@ export enum MutationTypes { SET_SERVER_CONFIGURATION = 'setServerConfiguration', SET_SERVER_CONFIGURATION_HASH = 'setServerConfigurationHash', - CLEAR_SERVER_CONFIGURATION_HASH = 'clearServerConfigurationHash', SET_SERVER_MESSAGES = 'setServerMessages', SET_WORLDS = 'setWorlds', SET_COMPONENTS = 'setComponents', diff --git a/src/store/mutations.ts b/src/store/mutations.ts index 4a7d128..3bed1dd 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -53,7 +53,6 @@ export type Mutations = { [MutationTypes.INIT](state: S, config: LiveAtlasGlobalConfig): void [MutationTypes.SET_SERVER_CONFIGURATION](state: S, config: LiveAtlasServerConfig): void [MutationTypes.SET_SERVER_CONFIGURATION_HASH](state: S, hash: number): void - [MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: S): void [MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void [MutationTypes.SET_WORLDS](state: S, worlds: Array): void [MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void @@ -188,11 +187,6 @@ export const mutations: MutationTree & Mutations = { state.configurationHash = hash; }, - // Sets configuration hash - [MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: State) { - state.configurationHash = undefined; - }, - // Sets messages from the initial config fetch [MutationTypes.SET_SERVER_MESSAGES](state: State, messages: LiveAtlasServerMessageConfig) { state.messages = Object.assign(state.messages, messages); @@ -650,6 +644,7 @@ export const mutations: MutationTree & Mutations = { state.currentWorldState.raining = false; state.currentWorldState.thundering = false; + state.configurationHash = undefined; state.configuration.title = ''; state.components.markers.showLabels= false;