From 9f6cc616ad69d9ddea36c248825be5351ee2214f Mon Sep 17 00:00:00 2001 From: Sirttas Date: Sun, 21 Jun 2026 12:41:32 +0200 Subject: [PATCH] auto refresh --- src/composables/index.ts | 1 + src/composables/useAutoRefresh.ts | 30 +++++++++++++++++++ .../AcquisitionQuantilsTooltip.vue | 13 ++++---- src/pages/market/Acquisitions.vue | 14 ++++++--- 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/composables/index.ts create mode 100644 src/composables/useAutoRefresh.ts diff --git a/src/composables/index.ts b/src/composables/index.ts new file mode 100644 index 0000000..e91ed36 --- /dev/null +++ b/src/composables/index.ts @@ -0,0 +1 @@ +export { useAutoRefresh } from './useAutoRefresh'; \ No newline at end of file diff --git a/src/composables/useAutoRefresh.ts b/src/composables/useAutoRefresh.ts new file mode 100644 index 0000000..c07db82 --- /dev/null +++ b/src/composables/useAutoRefresh.ts @@ -0,0 +1,30 @@ +import {onUnmounted, ref} from "vue"; + +const DEFAULT_INTERVAL = 1_000; + +export const useAutoRefresh = (callback: () => void | Promise, interval: number = DEFAULT_INTERVAL) => { + const active = ref(false); + let timer: ReturnType | undefined; + + const stop = () => { + if (timer) { + clearInterval(timer); + timer = undefined; + } + active.value = false; + }; + + const start = () => { + if (active.value) { + return; + } + active.value = true; + timer = setInterval(callback, interval); + }; + + const toggle = () => active.value ? stop() : start(); + + onUnmounted(stop); + + return {active, start, stop, toggle}; +}; \ No newline at end of file diff --git a/src/market/acquisition/AcquisitionQuantilsTooltip.vue b/src/market/acquisition/AcquisitionQuantilsTooltip.vue index e4c238c..3beec75 100644 --- a/src/market/acquisition/AcquisitionQuantilsTooltip.vue +++ b/src/market/acquisition/AcquisitionQuantilsTooltip.vue @@ -47,9 +47,9 @@ watchEffect(async () => {