mirror of
https://github.com/ArthurDanjou/artsite.git
synced 2026-01-14 22:59:56 +01:00
Refactor Stats.vue to optimize computed values
Extracted reusable computed values for time, date, and hours to improve code clarity and maintainability. This change reduces duplication and ensures consistency across template usages.
This commit is contained in:
@@ -9,7 +9,9 @@ const { t } = useI18n({
|
||||
useScope: 'local',
|
||||
})
|
||||
|
||||
const formatDate = (date: Date, format: string) => useDateFormat(date, format, { locales: currentLocale.value?.code ?? 'en' }).value
|
||||
const time = useTimeAgo(new Date(stats.value!.coding.data.range.start)).value.split(' ')[0]
|
||||
const date = useDateFormat(new Date(stats.value!.coding.data.range.start), 'DD MMMM YYYY', { locales: currentLocale.value?.code ?? 'en' })
|
||||
const hours = usePrecision(stats.value!.coding.data.grand_total.total_seconds_including_other_language / 3600, 0, { math: 'ceil' })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -20,18 +22,18 @@ const formatDate = (date: Date, format: string) => useDateFormat(date, format, {
|
||||
tag="p"
|
||||
>
|
||||
<template #time>
|
||||
{{ useTimeAgo(new Date(stats.coding.data.range.start)).value.split(' ')[0] }}
|
||||
{{ time }}
|
||||
</template>
|
||||
<template #date>
|
||||
<HoverText
|
||||
:hover="t('tooltip.date')"
|
||||
:text="formatDate(new Date(stats.coding.data.range.start), 'DD MMMM YYYY')"
|
||||
:text="date"
|
||||
/>
|
||||
</template>
|
||||
<template #hours>
|
||||
<HoverText
|
||||
:hover="t('tooltip.hours')"
|
||||
:text="usePrecision(stats.coding.data.grand_total.total_seconds_including_other_language / 3600, 0).value"
|
||||
:text="hours"
|
||||
/>
|
||||
</template>
|
||||
<template #editors>
|
||||
|
||||
Reference in New Issue
Block a user