From 6b88a6d19d8ba9c2dbcb5380c547457516afe380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Thu, 13 Apr 2023 12:34:53 +0900 Subject: [PATCH] chore: back to setTimeout --- packages/frontend/src/components/global/MkTime.vue | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/components/global/MkTime.vue b/packages/frontend/src/components/global/MkTime.vue index 1e60e3ee44..43665780f1 100644 --- a/packages/frontend/src/components/global/MkTime.vue +++ b/packages/frontend/src/components/global/MkTime.vue @@ -11,8 +11,6 @@ import { onUnmounted } from 'vue'; import { i18n } from '@/i18n'; import { dateTimeFormat } from '@/scripts/intl-const'; -import { defaultIdlingRenderScheduler } from '@/scripts/idle-render.js'; - const props = withDefaults(defineProps<{ time: Date | string | number | null; origin?: Date | null; @@ -46,16 +44,19 @@ const relative = $computed(() => { i18n.ts._ago.future); }); -function tick(): void { +let tickId: number; + +function tick() { now = props.origin ?? (new Date()).getTime(); + const ago = (now - _time) / 1000/*ms*/; + const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000; + tickId = window.setTimeout(tick, next); } if (props.mode === 'relative' || props.mode === 'detail') { tick(); - defaultIdlingRenderScheduler.add(tick); - onUnmounted(() => { - defaultIdlingRenderScheduler.delete(tick); + window.clearTimeout(tickId); }); }