From affeb347e5a0bc9b452bd8124e30ab6c74c4f76b Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Sun, 2 Feb 2025 19:17:53 +0100 Subject: [PATCH] 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. --- app/components/home/Stats.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/components/home/Stats.vue b/app/components/home/Stats.vue index 9aa294b..1a1a0f7 100644 --- a/app/components/home/Stats.vue +++ b/app/components/home/Stats.vue @@ -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' })