Reload config on hash change
This commit is contained in:
parent
f3913ef96b
commit
571534ca6e
18
src/App.vue
18
src/App.vue
@ -29,7 +29,6 @@ import {useStore} from "@/store";
|
|||||||
import {ActionTypes} from "@/store/action-types";
|
import {ActionTypes} from "@/store/action-types";
|
||||||
import {parseUrl} from '@/util';
|
import {parseUrl} from '@/util';
|
||||||
import {MutationTypes} from "@/store/mutation-types";
|
import {MutationTypes} from "@/store/mutation-types";
|
||||||
import API from '@/api';
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'App',
|
name: 'App',
|
||||||
@ -45,6 +44,7 @@ export default defineComponent({
|
|||||||
title = computed(() => store.state.configuration.title),
|
title = computed(() => store.state.configuration.title),
|
||||||
currentUrl = computed(() => store.getters.url),
|
currentUrl = computed(() => store.getters.url),
|
||||||
currentServer = computed(() => store.state.currentServer),
|
currentServer = computed(() => store.state.currentServer),
|
||||||
|
configurationHash = computed(() => store.state.configurationHash),
|
||||||
chatBoxEnabled = computed(() => store.state.components.chatBox),
|
chatBoxEnabled = computed(() => store.state.components.chatBox),
|
||||||
chatVisible = computed(() => store.state.ui.visibleElements.has('chat')),
|
chatVisible = computed(() => store.state.ui.visibleElements.has('chat')),
|
||||||
updatesEnabled = ref(false),
|
updatesEnabled = ref(false),
|
||||||
@ -54,7 +54,7 @@ export default defineComponent({
|
|||||||
loadConfiguration = () => {
|
loadConfiguration = () => {
|
||||||
return store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
|
return store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
|
||||||
startUpdates();
|
startUpdates();
|
||||||
requestAnimationFrame(window.hideSplash);
|
requestAnimationFrame(() => window.hideSplash());
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.error('Failed to load server configuration: ', e);
|
console.error('Failed to load server configuration: ', e);
|
||||||
window.showSplashError(e, false, ++configAttempts.value);
|
window.showSplashError(e, false, ++configAttempts.value);
|
||||||
@ -115,11 +115,23 @@ export default defineComponent({
|
|||||||
watch(currentServer, (newServer) => {
|
watch(currentServer, (newServer) => {
|
||||||
window.showSplash();
|
window.showSplash();
|
||||||
stopUpdates();
|
stopUpdates();
|
||||||
window.history.replaceState({}, '', newServer);
|
|
||||||
|
//Cleanup
|
||||||
|
store.commit(MutationTypes.CLEAR_PLAYERS, undefined);
|
||||||
|
store.commit(MutationTypes.CLEAR_CURRENT_MAP, undefined);
|
||||||
store.commit(MutationTypes.CLEAR_PARSED_URL, undefined);
|
store.commit(MutationTypes.CLEAR_PARSED_URL, undefined);
|
||||||
|
|
||||||
|
window.history.replaceState({}, '', newServer);
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
});
|
});
|
||||||
|
watch(configurationHash, (newHash, oldHash) => {
|
||||||
|
if(newHash && oldHash) {
|
||||||
|
window.showSplash();
|
||||||
|
stopUpdates();
|
||||||
|
store.commit(MutationTypes.CLEAR_PARSED_URL, undefined);
|
||||||
|
loadConfiguration();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(() => loadConfiguration());
|
onMounted(() => loadConfiguration());
|
||||||
onBeforeUnmount(() => stopUpdates());
|
onBeforeUnmount(() => stopUpdates());
|
||||||
|
@ -726,7 +726,7 @@ export default {
|
|||||||
raining: response.hasStorm || false,
|
raining: response.hasStorm || false,
|
||||||
},
|
},
|
||||||
playerCount: response.count || 0,
|
playerCount: response.count || 0,
|
||||||
configHash: response.configHash || 0,
|
configHash: response.confighash || 0,
|
||||||
timestamp: response.timestamp || 0,
|
timestamp: response.timestamp || 0,
|
||||||
players,
|
players,
|
||||||
updates: buildUpdates(response.updates || []),
|
updates: buildUpdates(response.updates || []),
|
||||||
|
@ -78,9 +78,8 @@ export interface Actions {
|
|||||||
|
|
||||||
export const actions: ActionTree<State, State> & Actions = {
|
export const actions: ActionTree<State, State> & Actions = {
|
||||||
[ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise<DynmapConfigurationResponse> {
|
[ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise<DynmapConfigurationResponse> {
|
||||||
//Cleanup in case we are switching servers
|
//Clear any existing has to avoid triggering a second config load, after this load changes the hash
|
||||||
commit(MutationTypes.CLEAR_PLAYERS, undefined);
|
commit(MutationTypes.CLEAR_CONFIGURATION_HASH, undefined);
|
||||||
commit(MutationTypes.CLEAR_CURRENT_MAP, undefined);
|
|
||||||
|
|
||||||
return API.getConfiguration().then(config => {
|
return API.getConfiguration().then(config => {
|
||||||
commit(MutationTypes.SET_CONFIGURATION, config.config);
|
commit(MutationTypes.SET_CONFIGURATION, config.config);
|
||||||
@ -89,6 +88,11 @@ export const actions: ActionTree<State, State> & Actions = {
|
|||||||
commit(MutationTypes.SET_COMPONENTS, config.components);
|
commit(MutationTypes.SET_COMPONENTS, config.components);
|
||||||
commit(MutationTypes.SET_LOGGED_IN, config.loggedIn);
|
commit(MutationTypes.SET_LOGGED_IN, config.loggedIn);
|
||||||
|
|
||||||
|
//Skip default map/ui visibility logic if we already have a map selected (i.e config reload after hash change)
|
||||||
|
if(state.currentMap) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
if(state.configuration.expandUI && !state.ui.smallScreen) {
|
if(state.configuration.expandUI && !state.ui.smallScreen) {
|
||||||
commit(MutationTypes.SET_UI_ELEMENT_VISIBILITY, {element: 'players', state: true});
|
commit(MutationTypes.SET_UI_ELEMENT_VISIBILITY, {element: 'players', state: true});
|
||||||
commit(MutationTypes.SET_UI_ELEMENT_VISIBILITY, {element: 'maps', state: true});
|
commit(MutationTypes.SET_UI_ELEMENT_VISIBILITY, {element: 'maps', state: true});
|
||||||
@ -151,6 +155,7 @@ export const actions: ActionTree<State, State> & Actions = {
|
|||||||
commit(MutationTypes.ADD_MARKER_SET_UPDATES, update.updates.markerSets);
|
commit(MutationTypes.ADD_MARKER_SET_UPDATES, update.updates.markerSets);
|
||||||
commit(MutationTypes.ADD_TILE_UPDATES, update.updates.tiles);
|
commit(MutationTypes.ADD_TILE_UPDATES, update.updates.tiles);
|
||||||
commit(MutationTypes.ADD_CHAT, update.updates.chat);
|
commit(MutationTypes.ADD_CHAT, update.updates.chat);
|
||||||
|
commit(MutationTypes.SET_CONFIGURATION_HASH, update.configHash);
|
||||||
|
|
||||||
return dispatch(ActionTypes.SET_PLAYERS, update.players).then(() => {
|
return dispatch(ActionTypes.SET_PLAYERS, update.players).then(() => {
|
||||||
return update;
|
return update;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
export enum MutationTypes {
|
export enum MutationTypes {
|
||||||
SET_SERVERS ='setServers',
|
SET_SERVERS ='setServers',
|
||||||
SET_CONFIGURATION = 'setConfiguration',
|
SET_CONFIGURATION = 'setConfiguration',
|
||||||
|
SET_CONFIGURATION_HASH = 'setConfigurationHash',
|
||||||
|
CLEAR_CONFIGURATION_HASH = 'clearConfigurationHash',
|
||||||
SET_MESSAGES = 'setMessages',
|
SET_MESSAGES = 'setMessages',
|
||||||
SET_WORLDS = 'setWorlds',
|
SET_WORLDS = 'setWorlds',
|
||||||
SET_COMPONENTS = 'setComponents',
|
SET_COMPONENTS = 'setComponents',
|
||||||
|
@ -42,6 +42,8 @@ export type CurrentMapPayload = {
|
|||||||
export type Mutations<S = State> = {
|
export type Mutations<S = State> = {
|
||||||
[MutationTypes.SET_SERVERS](state: S, servers: Map<string, LiveAtlasServerDefinition>): void
|
[MutationTypes.SET_SERVERS](state: S, servers: Map<string, LiveAtlasServerDefinition>): void
|
||||||
[MutationTypes.SET_CONFIGURATION](state: S, config: DynmapServerConfig): void
|
[MutationTypes.SET_CONFIGURATION](state: S, config: DynmapServerConfig): void
|
||||||
|
[MutationTypes.SET_CONFIGURATION_HASH](state: S, hash: number): void
|
||||||
|
[MutationTypes.CLEAR_CONFIGURATION_HASH](state: S): void
|
||||||
[MutationTypes.SET_MESSAGES](state: S, messages: DynmapMessageConfig): void
|
[MutationTypes.SET_MESSAGES](state: S, messages: DynmapMessageConfig): void
|
||||||
[MutationTypes.SET_WORLDS](state: S, worlds: Array<DynmapWorld>): void
|
[MutationTypes.SET_WORLDS](state: S, worlds: Array<DynmapWorld>): void
|
||||||
[MutationTypes.SET_COMPONENTS](state: S, worlds: DynmapComponentConfig): void
|
[MutationTypes.SET_COMPONENTS](state: S, worlds: DynmapComponentConfig): void
|
||||||
@ -96,6 +98,17 @@ export const mutations: MutationTree<State> & Mutations = {
|
|||||||
// Sets configuration options from the initial config fetch
|
// Sets configuration options from the initial config fetch
|
||||||
[MutationTypes.SET_CONFIGURATION](state: State, config: DynmapServerConfig) {
|
[MutationTypes.SET_CONFIGURATION](state: State, config: DynmapServerConfig) {
|
||||||
state.configuration = Object.assign(state.configuration, config);
|
state.configuration = Object.assign(state.configuration, config);
|
||||||
|
state.configurationHash = config.hash;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Sets configuration hash
|
||||||
|
[MutationTypes.SET_CONFIGURATION_HASH](state: State, hash: number) {
|
||||||
|
state.configurationHash = hash;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Sets configuration hash
|
||||||
|
[MutationTypes.CLEAR_CONFIGURATION_HASH](state: State) {
|
||||||
|
state.configurationHash = undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
//Set messsages from the initial config fetch
|
//Set messsages from the initial config fetch
|
||||||
@ -108,8 +121,6 @@ export const mutations: MutationTree<State> & Mutations = {
|
|||||||
state.worlds.clear();
|
state.worlds.clear();
|
||||||
state.maps.clear();
|
state.maps.clear();
|
||||||
|
|
||||||
state.currentMap = undefined;
|
|
||||||
state.currentWorld = undefined;
|
|
||||||
state.followTarget = undefined;
|
state.followTarget = undefined;
|
||||||
state.panTarget = undefined;
|
state.panTarget = undefined;
|
||||||
|
|
||||||
@ -121,6 +132,20 @@ export const mutations: MutationTree<State> & Mutations = {
|
|||||||
state.worlds.set(world.name, world);
|
state.worlds.set(world.name, world);
|
||||||
world.maps.forEach(map => state.maps.set([world.name, map.name].join('_'), map));
|
world.maps.forEach(map => state.maps.set([world.name, map.name].join('_'), map));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Update current world if a world with the same name still exists, otherwise clear
|
||||||
|
if(state.currentWorld && state.worlds.has(state.currentWorld.name)) {
|
||||||
|
state.currentWorld = state.worlds.get(state.currentWorld.name);
|
||||||
|
} else {
|
||||||
|
state.currentWorld = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update current map if a map with the same name still exists, otherwise clear
|
||||||
|
if(state.currentWorld && state.currentMap && state.maps.has([state.currentWorld.name, state.currentMap.name].join('_'))) {
|
||||||
|
state.currentMap = state.maps.get([state.currentWorld.name, state.currentMap.name].join('_'));
|
||||||
|
} else {
|
||||||
|
state.currentMap = undefined;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//Sets the state and settings of optional components, from the initial config fetch
|
//Sets the state and settings of optional components, from the initial config fetch
|
||||||
|
@ -29,6 +29,7 @@ export type State = {
|
|||||||
version: string;
|
version: string;
|
||||||
servers: Map<string, LiveAtlasServerDefinition>;
|
servers: Map<string, LiveAtlasServerDefinition>;
|
||||||
configuration: DynmapServerConfig;
|
configuration: DynmapServerConfig;
|
||||||
|
configurationHash: number | undefined;
|
||||||
messages: DynmapMessageConfig;
|
messages: DynmapMessageConfig;
|
||||||
components: DynmapComponentConfig;
|
components: DynmapComponentConfig;
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ export const state: State = {
|
|||||||
expandUI: false,
|
expandUI: false,
|
||||||
hash: 0,
|
hash: 0,
|
||||||
},
|
},
|
||||||
|
configurationHash: undefined,
|
||||||
|
|
||||||
messages: {
|
messages: {
|
||||||
chatNotAllowed: '',
|
chatNotAllowed: '',
|
||||||
|
Loading…
Reference in New Issue
Block a user