feat: impl IdleRender

This commit is contained in:
Acid Chicken (硫酸鶏) 2023-04-09 14:08:58 +09:00
parent 2b19e1f732
commit b346b99527
No known key found for this signature in database
GPG key ID: 3E87B98A3F6BAB99
6 changed files with 89 additions and 34 deletions

View file

@ -11,6 +11,7 @@
import { onUnmounted } from 'vue';
import { i18n } from '@/i18n';
import { dateTimeFormat } from '@/scripts/intl-const';
import { defaultIdleRender } from '@/scripts/idle-render.js';
const props = withDefaults(defineProps<{
time: Date | string | number | null;
@ -45,21 +46,16 @@ const relative = $computed<string>(() => {
i18n.ts._ago.future);
});
let tickId: number;
function tick() {
function tick(): void {
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();
defaultIdleRender.add(tick);
onUnmounted(() => {
window.clearTimeout(tickId);
defaultIdleRender.delete(tick);
});
}
</script>