From b39716a199fa7573f1bdace79b965606de9f1eb6 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 24 Jul 2023 19:13:29 +0200 Subject: [PATCH] client: make time components computed Previously, if a property of the `MkTime` component was changed the displayed value would not update because the necessary values were computed once on setup and not made `$computed` so they would be re-computed when necessary. --- packages/client/src/components/global/time.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/src/components/global/time.vue b/packages/client/src/components/global/time.vue index f7254308c..82dbb4c6d 100644 --- a/packages/client/src/components/global/time.vue +++ b/packages/client/src/components/global/time.vue @@ -23,15 +23,15 @@ const props = withDefaults(defineProps<{ utc: false, }); -const _time = typeof props.time === 'string' ? new Date(props.time) : props.time; -const absolute = ((): string => { +const _time = $computed((): Date => typeof props.time === 'string' ? new Date(props.time) : props.time); +const absolute = $computed((): string => { const options = props.utc ? { timeZone: 'UTC' } : {}; switch (props.format) { case 'date': return _time.toLocaleDateString(lang ?? 'en-US', options); case 'time': return _time.toLocaleTimeString(lang ?? 'en-US', options); default: return _time.toLocaleString(lang ?? 'en-US', options); } -})(); +}); let now = $ref(new Date()); const relative = $computed(() => {