Store and clear loadConfiguration timeouts

- Avoids double loads if switching servers right after a config load has failed
This commit is contained in:
James Lyne 2021-08-31 17:45:05 +01:00
parent 3cb9f8f315
commit ca60f2bb09

View File

@ -46,6 +46,8 @@ export default defineComponent({
},
setup() {
let loadingTimeout = 0;
const store = useStore(),
title = computed(() => store.getters.pageTitle),
currentUrl = computed(() => store.getters.url),
@ -61,6 +63,7 @@ export default defineComponent({
loadConfiguration = async () => {
try {
clearTimeout(loadingTimeout);
showSplash();
loading.value = true;
@ -95,7 +98,9 @@ export default defineComponent({
const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`;
console.error(`${error}:`, e);
showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value);
setTimeout(() => loadConfiguration(), 1000);
clearTimeout(loadingTimeout);
loadingTimeout = setTimeout(() => loadConfiguration(), 1000);
} finally {
loading.value = false;
}
@ -184,7 +189,10 @@ export default defineComponent({
})
onMounted(() => loadConfiguration());
onBeforeUnmount(() => store.dispatch(ActionTypes.STOP_UPDATES, undefined));
onBeforeUnmount(() => {
store.dispatch(ActionTypes.STOP_UPDATES, undefined);
clearTimeout(loadingTimeout);
});
handleUrl();
onResize();