fix(duration): Values greater than a month weren't displayed (#1381)

This commit is contained in:
Rémi Marseault 2023-12-02 21:05:26 +01:00 committed by GitHub
parent 8abda97341
commit 8ba6d120c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 15 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import dayjs from '@/plugins/dayjs.ts'
import dayjs from '@/plugins/dayjs'
import { useVueTorrentStore } from '@/stores'
import { Torrent } from '@/types/vuetorrent'

View file

@ -1,10 +1,34 @@
<script setup lang="ts">
import dayjs from '@/plugins/dayjs'
import { Torrent } from '@/types/vuetorrent'
import dayjs from '@/plugins/dayjs.ts'
import { computed } from 'vue'
defineProps<{ torrent: Torrent; title: string; value: string }>()
const props = defineProps<{ torrent: Torrent; title: string; value: string }>()
const durationFormat = 'D[d] H[h] m[m] s[s]'
const formattedDuration = computed(() => {
const duration = dayjs.duration(props.torrent[props.value], 'seconds')
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(' ')
})
</script>
<template>
@ -14,7 +38,7 @@ const durationFormat = 'D[d] H[h] m[m] s[s]'
</div>
<div>
<span v-if="torrent[value] > 0">
{{ dayjs.duration(torrent[value], 'seconds').format(durationFormat) }}
{{ formattedDuration }}
</span>
<span v-else>{{ $t('dashboard.not_complete') }}</span>
</div>

View file

@ -1,6 +1,6 @@
<script setup lang="ts">
import { Torrent } from '@/types/vuetorrent'
import dayjs from '@/plugins/dayjs.ts'
import dayjs from '@/plugins/dayjs'
defineProps<{ torrent: Torrent; title: string; value: string }>()
</script>

View file

@ -1,6 +1,6 @@
<script lang="ts" setup>
import GridTorrent from '@/components/Dashboard/Views/Grid/GridTorrent.vue'
import { useDashboardStore } from '@/stores/dashboard.ts'
import { useDashboardStore } from '@/stores'
import { Torrent as TorrentType } from '@/types/vuetorrent'
import { useDisplay } from 'vuetify'

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import dayjs from '@/plugins/dayjs.ts'
import dayjs from '@/plugins/dayjs'
import { useVueTorrentStore } from '@/stores'
import { Torrent } from '@/types/vuetorrent'

View file

@ -1,15 +1,39 @@
<script setup lang="ts">
import dayjs from '@/plugins/dayjs.ts'
import dayjs from '@/plugins/dayjs'
import { Torrent } from '@/types/vuetorrent'
import { computed } from 'vue'
defineProps<{ torrent: Torrent; title: string; value: string }>()
const props = defineProps<{ torrent: Torrent; title: string; value: string }>()
const durationFormat = 'D[d] H[h] m[m] s[s]'
const formattedDuration = computed(() => {
const duration = dayjs.duration(props.torrent[props.value], 'seconds')
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(' ')
})
</script>
<template>
<td v-if="torrent[value] > 0">
{{ dayjs.duration(torrent[value], 'seconds').format(durationFormat) }}
{{ formattedDuration }}
</td>
<td v-else>{{ $t('dashboard.not_complete') }}</td>
</template>

View file

@ -1,7 +1,6 @@
<script lang="ts" setup>
import TableTorrent from '@/components/Dashboard/Views/Table/TableTorrent.vue'
import { useVueTorrentStore } from '@/stores'
import { useDashboardStore } from '@/stores/dashboard.ts'
import { useDashboardStore, useVueTorrentStore } from '@/stores'
import { Torrent as TorrentType } from '@/types/vuetorrent'
import { computed } from 'vue'

View file

@ -1,4 +1,4 @@
import { NetworkInterface } from '@/types/qbit/models/AppPreferences.ts'
import { NetworkInterface } from '@/types/qbit/models/AppPreferences'
import type { AxiosInstance } from 'axios'
import axios from 'axios'
import type {