-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Add configurable format for duration values (#1826)
- Loading branch information
Showing
11 changed files
with
108 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 7 additions & 20 deletions
27
src/components/Dashboard/Views/Table/DashboardItems/ItemDuration.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,21 @@ | ||
<script setup lang="ts"> | ||
import dayjs from '@/plugins/dayjs' | ||
import { formatDuration } from '@/helpers' | ||
import { useVueTorrentStore } from '@/stores' | ||
import { Torrent } from '@/types/vuetorrent' | ||
import { computed } from 'vue' | ||
import { DurationUnitType } from 'dayjs/plugin/duration' | ||
import { storeToRefs } from 'pinia' | ||
import { computed } from 'vue' | ||
const props = defineProps<{ torrent: Torrent; unit: DurationUnitType; value: (t: Torrent) => number }>() | ||
const val = computed(() => props.value(props.torrent)) | ||
const formattedDuration = computed(() => { | ||
const duration = dayjs.duration(val.value, props.unit) | ||
const { durationFormat } = storeToRefs(useVueTorrentStore()) | ||
const durationValues = [duration.years(), duration.months(), duration.days(), duration.hours(), duration.minutes(), duration.seconds()] | ||
const durationLabels = ['Y', 'M', 'd', 'h', 'm', 's'] | ||
let flag = false | ||
return durationValues | ||
.map((value, index) => { | ||
if (flag || value) { | ||
flag = true | ||
return `${value}${durationLabels[index]}` | ||
} | ||
}) | ||
.filter(value => value) | ||
.join(' ') | ||
}) | ||
const val = computed(() => props.value(props.torrent)) | ||
</script> | ||
|
||
<template> | ||
<td v-if="val > 0" class="text-no-wrap"> | ||
{{ formattedDuration }} | ||
{{ formatDuration(val, props.unit, durationFormat) }} | ||
</td> | ||
<td v-else class="text-no-wrap">{{ $t('common.NA') }}</td> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters