From ca8fad305531ab11e933566e4a749571e9db9245 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 19 Aug 2023 15:41:57 -0700 Subject: [PATCH] timeline: prevent negative loading count Signed-off-by: Varun Patil --- src/components/Timeline.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index e2d788ae..9f013c40 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -281,8 +281,8 @@ export default defineComponent({ } }, - updateLoading(delta: number) { - this.loading += delta; + updateLoading(delta: number): void { + this.loading = Math.max(0, this.loading + delta); }, isMobile() { @@ -642,14 +642,14 @@ export default defineComponent({ // Awaiting this is important because the folders must render // before the timeline to prevent glitches try { - this.loading++; + this.updateLoading(1); const state = this.state; // @ts-ignore const res = await this.$refs.dtm.refresh(); if (this.state !== state) return; this.dtmContent = res; } finally { - this.loading--; + this.updateLoading(-1); } // Get URL an cache identifier @@ -668,7 +668,7 @@ export default defineComponent({ let cache: IDay[] | null = null; try { - this.loading++; + this.updateLoading(1); const startState = this.state; let data: IDay[] = []; @@ -687,7 +687,7 @@ export default defineComponent({ } await this.processDays(cache); - this.loading--; + this.updateLoading(-1); } } catch { console.warn(`Failed to process days cache: ${cacheUrl}`); @@ -719,7 +719,7 @@ export default defineComponent({ } } finally { // If cache is set here, loading was already decremented - if (!cache) this.loading--; + if (!cache) this.updateLoading(-1); } },