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.
This commit is contained in:
Johann150 2023-07-24 19:13:29 +02:00
parent dbe2b7611d
commit b39716a199
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -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(() => {