Refactor App component, apply configured page title
This commit is contained in:
parent
b5454b1e97
commit
f45dcd4ae8
69
src/App.vue
69
src/App.vue
@ -4,75 +4,60 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent, computed, ref} from 'vue';
|
||||
import {defineComponent, computed, ref, onMounted, onBeforeUnmount, watch} from 'vue';
|
||||
import Map from './components/Map.vue';
|
||||
import Sidebar from './components/Sidebar.vue';
|
||||
import {useStore} from "./store";
|
||||
import {ActionTypes} from "@/store/action-types";
|
||||
|
||||
export default defineComponent({
|
||||
name: 'WorldList',
|
||||
name: 'App',
|
||||
components: {
|
||||
Map,
|
||||
Sidebar,
|
||||
},
|
||||
|
||||
setup() {
|
||||
let store = useStore(),
|
||||
const store = useStore(),
|
||||
updateInterval = computed(() => store.state.configuration.updateInterval),
|
||||
title = computed(() => store.state.configuration.title),
|
||||
updatesEnabled = ref(false),
|
||||
updateTimeout = ref(0);
|
||||
updateTimeout = ref(0),
|
||||
|
||||
return {
|
||||
store,
|
||||
updateInterval,
|
||||
updatesEnabled,
|
||||
updateTimeout
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.loadConfiguration();
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.stopUpdates();
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadConfiguration() {
|
||||
useStore().dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
|
||||
this.startUpdates();
|
||||
loadConfiguration = () => {
|
||||
store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
|
||||
startUpdates();
|
||||
window.hideSplash();
|
||||
});
|
||||
},
|
||||
|
||||
startUpdates() {
|
||||
this.updatesEnabled = true;
|
||||
this.update();
|
||||
startUpdates = () => {
|
||||
updatesEnabled.value = true;
|
||||
update();
|
||||
},
|
||||
|
||||
update() {
|
||||
useStore().dispatch(ActionTypes.GET_UPDATE, undefined).then(() => {
|
||||
if(this.updatesEnabled) {
|
||||
this.updateTimeout = setTimeout(() => this.update(), this.updateInterval);
|
||||
update = () => {
|
||||
store.dispatch(ActionTypes.GET_UPDATE, undefined).then(() => {
|
||||
if(updatesEnabled.value) {
|
||||
updateTimeout.value = setTimeout(() => update(), updateInterval.value);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
stopUpdates() {
|
||||
this.updatesEnabled = false;
|
||||
stopUpdates = () => {
|
||||
updatesEnabled.value = false;
|
||||
|
||||
if (this.updateTimeout) {
|
||||
clearTimeout(this.updateTimeout);
|
||||
if (updateTimeout.value) {
|
||||
clearTimeout(updateTimeout.value);
|
||||
}
|
||||
|
||||
this.updateTimeout = 0;
|
||||
}
|
||||
}
|
||||
updateTimeout.value = 0;
|
||||
};
|
||||
|
||||
watch(title, (title) => document.title = title);
|
||||
|
||||
onMounted(() => loadConfiguration());
|
||||
onBeforeUnmount(() => stopUpdates());
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
DynmapConfigurationResponse, DynmapLineUpdate,
|
||||
DynmapMarkerSet,
|
||||
DynmapMarkerUpdate,
|
||||
DynmapPlayer, DynmapTileUpdate,
|
||||
DynmapPlayer, DynmapServerConfig, DynmapTileUpdate,
|
||||
DynmapUpdateResponse
|
||||
} from "@/dynmap";
|
||||
|
||||
@ -57,7 +57,7 @@ export interface Actions {
|
||||
}
|
||||
|
||||
export const actions: ActionTree<State, State> & Actions = {
|
||||
[ActionTypes.LOAD_CONFIGURATION]({commit}) {
|
||||
[ActionTypes.LOAD_CONFIGURATION]({commit}): Promise<DynmapConfigurationResponse> {
|
||||
return API.getConfiguration().then(config => {
|
||||
commit(MutationTypes.SET_CONFIGURATION, config.config);
|
||||
commit(MutationTypes.SET_MESSAGES, config.messages);
|
||||
|
Loading…
Reference in New Issue
Block a user