Line data Source code
1 : <script setup lang="ts">
2 : import { computed } from 'vue'
3 : import { useI18n } from 'vue-i18n'
4 :
5 : import Loader from '@/components/loader/Loader.vue'
6 : import Badge from '@comfyorg/design-system/badge/Badge'
7 : import Button from '@comfyorg/design-system/button/Button'
8 : import type { TaskId } from '@/platform/tasks/services/taskService'
9 : import type { AssetDownload } from '@/stores/assetDownloadStore'
10 : import { isDownloadCancelled } from '@/stores/assetDownloadStore'
11 : import { cn } from '@comfyorg/tailwind-utils'
12 :
13 : const { job, isCancelling = false } = defineProps<{
14 : job: AssetDownload
15 : isCancelling?: boolean
16 : }>()
17 2355 : const emit = defineEmits<{ cancel: [taskId: TaskId] }>()
18 :
19 10 : const { t } = useI18n()
20 :
21 10 : const progressPercent = computed(() => Math.round(job.progress * 100))
22 10 : const isCompleted = computed(() => job.status === 'completed')
23 10 : const isFailed = computed(() => job.status === 'failed')
24 10 : const isRunning = computed(() => job.status === 'running')
25 10 : const isPending = computed(() => job.status === 'created')
26 10 : const isCancelled = computed(() => isDownloadCancelled(job.status))
27 10 : </script>
28 :
29 : <template>
30 20 : <div
31 : class="flex items-center justify-between rounded-lg bg-secondary px-4 py-3"
32 : >
33 : <div :class="cn('min-w-0 flex-1', isCompleted && 'opacity-50')">
34 : <span class="block truncate text-sm">{{ job.assetName }}</span>
35 : </div>
36 :
37 : <div class="flex shrink-0 items-center gap-2">
38 : <template v-if="isFailed">
39 : <i class="icon-[lucide--circle-alert] text-destructive" />
40 : <Badge variant="label" severity="danger">
41 : {{ t('progressToast.failed') }}
42 : </Badge>
43 : </template>
44 :
45 : <template v-else-if="isCompleted">
46 : <Badge variant="label" severity="contrast">
47 : {{ t('progressToast.finished') }}
48 : </Badge>
49 : </template>
50 :
51 : <template v-else-if="isCancelled">
52 : <Badge variant="label" severity="secondary">
53 : {{ t('electronFileDownload.cancelled') }}
54 : </Badge>
55 : </template>
56 :
57 : <template v-else-if="isRunning">
58 : <Loader size="sm" class="text-foreground" />
59 : <span class="text-xs"> {{ progressPercent }}% </span>
60 : </template>
61 :
62 : <template v-else-if="isPending">
63 : <span class="text-xs text-muted-foreground">
64 : {{ t('progressToast.pending') }}
65 : </span>
66 : </template>
67 :
68 : <Button
69 : v-if="isRunning || isPending"
70 : variant="muted-textonly"
71 : size="sm"
72 : :aria-label="t('electronFileDownload.cancel')"
73 : :disabled="isCancelling"
74 : @click="emit('cancel', job.taskId)"
75 : >
76 : {{ t('g.cancel') }}
77 : </Button>
78 : </div>
79 : </div>
80 : </template>
|