From 2ab569c18fbba9ddf411f32bda425b0a047d412f Mon Sep 17 00:00:00 2001 From: James Lyne Date: Thu, 20 May 2021 00:06:57 +0100 Subject: [PATCH] Refactor state.currentServer to contain the server config instead of just the ID. Abstract API away from actions. --- src/App.vue | 11 ++++++++--- src/components/sidebar/ServerListItem.vue | 6 +++--- src/store/actions.ts | 10 +++++----- src/store/getters.ts | 2 +- src/store/mutations.ts | 4 ++-- src/store/state.ts | 2 +- src/util.ts | 13 ++++++++++++- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/App.vue b/src/App.vue index 6414a8a..1191d27 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,6 +29,7 @@ import {useStore} from "@/store"; import {ActionTypes} from "@/store/action-types"; import {parseUrl} from '@/util'; import {MutationTypes} from "@/store/mutation-types"; +import {LiveAtlasServerDefinition} from "@/index"; export default defineComponent({ name: 'App', @@ -62,7 +63,7 @@ export default defineComponent({ return; } - const error = `Failed to load server configuration for '${store.state.currentServer}'`; + const error = `Failed to load server configuration for '${store.state.currentServer.id}'`; console.error(`${error}:`, e); window.showSplashError(`${error}\n${e}`, false, ++configAttempts.value); setTimeout(() => loadConfiguration(), 1000); @@ -125,16 +126,20 @@ export default defineComponent({ watch(title, (title) => document.title = title); watch(currentUrl, (url) => window.history.replaceState({}, '', url)); - watch(currentServer, (newServer) => { + watch(currentServer, (newServer: LiveAtlasServerDefinition) => { window.showSplash(); stopUpdates(); + if(!newServer) { + return; + } + //Cleanup store.commit(MutationTypes.CLEAR_PLAYERS, undefined); store.commit(MutationTypes.CLEAR_CURRENT_MAP, undefined); store.commit(MutationTypes.CLEAR_PARSED_URL, undefined); - window.history.replaceState({}, '', newServer); + window.history.replaceState({}, '', newServer.id); loadConfiguration(); }); watch(configurationHash, (newHash, oldHash) => { diff --git a/src/components/sidebar/ServerListItem.vue b/src/components/sidebar/ServerListItem.vue index 1388a13..d2a192d 100644 --- a/src/components/sidebar/ServerListItem.vue +++ b/src/components/sidebar/ServerListItem.vue @@ -15,8 +15,8 @@ -->