koel/resources/assets/js/components/ui/upload/UploadItem.vue

64 lines
2 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<div
:class="cssClass"
:title="file.message"
class="upload-item relative rounded min-h-[32px] overflow-hidden bg-k-bg-secondary"
>
<span
:style="{ width: `${file.progress}%` }"
class="absolute h-full top-0 left-0 z-0 duration-200 ease-out bg-k-highlight"
/>
<span class="details z-10 absolute h-full w-full flex items-center content-between">
<span class="name px-4 flex-1">{{ file.name }}</span>
<span class="flex items-center">
<span v-if="file.status === 'Errored'" v-koel-tooltip.left :title="file.message" class="info !px-3">
<Icon :icon="faInfoCircle" :title="file.message" />
</span>
2024-04-04 22:20:42 +00:00
<Btn v-if="canRetry" icon-only title="Retry" transparent unrounded class="!px-3" @click="retry">
2023-11-10 13:16:06 +00:00
<Icon :icon="faRotateBack" />
2022-04-15 14:24:30 +00:00
</Btn>
2024-04-04 22:20:42 +00:00
<Btn v-if="canRemove" icon-only title="Remove" transparent unrounded class="!px-3" @click="remove">
2023-11-10 13:16:06 +00:00
<Icon :icon="faTrashCan" />
2022-04-15 14:24:30 +00:00
</Btn>
</span>
</span>
</div>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import slugify from 'slugify'
import { faInfoCircle, faRotateBack, faTrashCan } from '@fortawesome/free-solid-svg-icons'
2022-04-15 17:00:08 +00:00
import { computed, defineAsyncComponent, toRefs } from 'vue'
import { UploadFile, uploadService } from '@/services'
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
const Btn = defineAsyncComponent(() => import('@/components/ui/form/Btn.vue'))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const props = defineProps<{ file: UploadFile }>()
const { file } = toRefs(props)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const canRetry = computed(() => file.value.status === 'Canceled' || file.value.status === 'Errored')
const canRemove = computed(() => file.value.status !== 'Uploading') // we're not supporting cancel tokens (yet).
const cssClass = computed(() => slugify(file.value.status).toLowerCase())
2022-04-15 14:24:30 +00:00
2022-04-24 08:50:45 +00:00
const remove = () => uploadService.remove(file.value)
const retry = () => uploadService.retry(file.value)
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2024-04-04 22:20:42 +00:00
.uploaded {
@apply bg-k-success;
2022-04-15 14:24:30 +00:00
.progress {
2024-04-04 22:20:42 +00:00
@apply bg-transparent;
2022-04-15 14:24:30 +00:00
}
2024-04-04 22:20:42 +00:00
}
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
.errored {
@apply bg-k-danger;
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
.progress {
@apply bg-transparent;
2022-04-15 14:24:30 +00:00
}
}
</style>