client: make time components computed
ci/woodpecker/push/lint-client Pipeline failed Details
ci/woodpecker/push/lint-backend Pipeline failed Details
ci/woodpecker/push/lint-foundkey-js Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/lint-sw Pipeline failed Details
ci/woodpecker/push/test Pipeline failed Details

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: Johann150
GPG Key ID: 9EE6577A2A06F8F1
1 changed files with 3 additions and 3 deletions

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