2020-11-20 18:43:30 +00:00
|
|
|
<template>
|
2020-12-01 23:20:38 +00:00
|
|
|
<Map></Map>
|
2020-11-23 12:13:28 +00:00
|
|
|
<Sidebar></Sidebar>
|
2020-11-20 18:43:30 +00:00
|
|
|
</template>
|
|
|
|
|
2020-11-20 21:47:56 +00:00
|
|
|
<script lang="ts">
|
2020-12-12 19:04:51 +00:00
|
|
|
import {defineComponent, computed, ref, onMounted, onBeforeUnmount, watch} from 'vue';
|
2020-12-01 23:20:38 +00:00
|
|
|
import Map from './components/Map.vue';
|
2020-11-23 12:13:28 +00:00
|
|
|
import Sidebar from './components/Sidebar.vue';
|
2020-11-23 16:16:26 +00:00
|
|
|
import {useStore} from "./store";
|
|
|
|
import {ActionTypes} from "@/store/action-types";
|
2020-12-13 02:50:17 +00:00
|
|
|
import Util from '@/util';
|
|
|
|
import {MutationTypes} from "@/store/mutation-types";
|
2020-11-23 12:13:28 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
2020-12-12 19:04:51 +00:00
|
|
|
name: 'App',
|
2020-11-23 12:13:28 +00:00
|
|
|
components: {
|
2020-12-01 23:20:38 +00:00
|
|
|
Map,
|
2020-11-23 12:13:28 +00:00
|
|
|
Sidebar,
|
|
|
|
},
|
|
|
|
|
|
|
|
setup() {
|
2020-12-13 02:50:17 +00:00
|
|
|
const initialUrl = window.location.hash.replace('#', ''),
|
|
|
|
store = useStore(),
|
2020-11-23 12:13:28 +00:00
|
|
|
updateInterval = computed(() => store.state.configuration.updateInterval),
|
2020-12-12 19:04:51 +00:00
|
|
|
title = computed(() => store.state.configuration.title),
|
2020-12-13 02:50:17 +00:00
|
|
|
currentUrl = computed(() => store.getters.url),
|
2020-11-23 12:13:28 +00:00
|
|
|
updatesEnabled = ref(false),
|
2020-12-12 19:04:51 +00:00
|
|
|
updateTimeout = ref(0),
|
|
|
|
|
|
|
|
loadConfiguration = () => {
|
|
|
|
store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined).then(() => {
|
|
|
|
startUpdates();
|
|
|
|
window.hideSplash();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
startUpdates = () => {
|
|
|
|
updatesEnabled.value = true;
|
|
|
|
update();
|
|
|
|
},
|
|
|
|
|
|
|
|
update = () => {
|
|
|
|
store.dispatch(ActionTypes.GET_UPDATE, undefined).then(() => {
|
|
|
|
if(updatesEnabled.value) {
|
|
|
|
updateTimeout.value = setTimeout(() => update(), updateInterval.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
stopUpdates = () => {
|
|
|
|
updatesEnabled.value = false;
|
|
|
|
|
|
|
|
if (updateTimeout.value) {
|
|
|
|
clearTimeout(updateTimeout.value);
|
2020-11-23 12:13:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 19:04:51 +00:00
|
|
|
updateTimeout.value = 0;
|
2020-12-13 02:50:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
parseUrl = () => {
|
|
|
|
if(!initialUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = Util.parseMapHash(initialUrl);
|
|
|
|
store.commit(MutationTypes.SET_PARSED_URL, result);
|
|
|
|
} catch(e) {
|
|
|
|
console.warn('Ignoring invalid url ' + e);
|
|
|
|
}
|
2020-12-12 19:04:51 +00:00
|
|
|
};
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-12-12 19:04:51 +00:00
|
|
|
watch(title, (title) => document.title = title);
|
2020-12-13 02:50:17 +00:00
|
|
|
watch(currentUrl, (url) => window.history.replaceState({}, '', url));
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-12-12 19:04:51 +00:00
|
|
|
onMounted(() => loadConfiguration());
|
|
|
|
onBeforeUnmount(() => stopUpdates());
|
2020-12-13 02:50:17 +00:00
|
|
|
|
|
|
|
parseUrl();
|
2020-12-12 19:04:51 +00:00
|
|
|
},
|
2020-11-23 12:13:28 +00:00
|
|
|
});
|
2020-11-20 18:43:30 +00:00
|
|
|
</script>
|