koel/resources/assets/js/components/screens/UploadScreen.vue

134 lines
3.8 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="uploadWrapper">
2022-07-16 15:44:45 +00:00
<ScreenHeader layout="collapsed">
2022-07-05 14:35:15 +00:00
Upload Media
2022-04-15 14:24:30 +00:00
2022-12-02 16:17:37 +00:00
<template #controls>
<BtnGroup v-if="hasUploadFailures" uppercased>
2022-04-21 18:39:18 +00:00
<Btn data-testid="upload-retry-all-btn" green @click="retryAll">
2023-11-10 13:16:06 +00:00
<Icon :icon="faRotateRight" />
2022-04-15 14:24:30 +00:00
Retry All
2022-04-15 17:00:08 +00:00
</Btn>
2022-04-21 18:39:18 +00:00
<Btn data-testid="upload-remove-all-btn" orange @click="removeFailedEntries">
2023-11-10 13:16:06 +00:00
<Icon :icon="faTrashCan" />
2022-04-15 14:24:30 +00:00
Remove Failed
2022-04-15 17:00:08 +00:00
</Btn>
</BtnGroup>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
</ScreenHeader>
2022-04-15 14:24:30 +00:00
<div v-koel-overflow-fade class="main-scroll-wrap">
2022-04-15 14:24:30 +00:00
<div
v-if="mediaPathSetUp"
2022-04-21 18:39:18 +00:00
:class="{ droppable }"
2022-04-15 14:24:30 +00:00
class="upload-panel"
@dragenter.prevent="onDragEnter"
@dragleave.prevent="onDragLeave"
@drop.prevent="onDrop"
2022-04-15 14:24:30 +00:00
@dragover.prevent
>
2022-12-02 16:17:37 +00:00
<div v-if="files.length" class="upload-files">
<UploadItem v-for="file in files" :key="file.id" :file="file" data-testid="upload-item" />
2022-04-15 14:24:30 +00:00
</div>
<ScreenEmptyState v-else>
2022-12-02 16:17:37 +00:00
<template #icon>
2023-11-10 13:16:06 +00:00
<Icon :icon="faUpload" />
2022-04-15 14:24:30 +00:00
</template>
2022-07-15 07:23:55 +00:00
{{ canDropFolders ? 'Drop files or folders to upload' : 'Drop files to upload' }}
2022-04-15 14:24:30 +00:00
<span class="secondary d-block">
<a class="or-click d-block" role="button">
or click here to select songs
2022-12-02 16:17:37 +00:00
<input :accept="acceptAttribute" multiple name="file[]" type="file" @change="onFileInputChange">
2022-04-15 14:24:30 +00:00
</a>
</span>
</ScreenEmptyState>
2022-04-15 14:24:30 +00:00
</div>
<ScreenEmptyState v-else>
2022-12-02 16:17:37 +00:00
<template #icon>
2023-11-10 13:16:06 +00:00
<Icon :icon="faWarning" />
2022-04-15 14:24:30 +00:00
</template>
No media path set.
</ScreenEmptyState>
2022-04-15 14:24:30 +00:00
</div>
</section>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { faRotateRight, faTrashCan, faUpload, faWarning } from '@fortawesome/free-solid-svg-icons'
2022-04-21 18:39:18 +00:00
import { computed, defineAsyncComponent, ref, toRef } from 'vue'
2022-04-15 14:24:30 +00:00
import { isDirectoryReadingSupported as canDropFolders } from '@/utils'
import { acceptedMediaTypes } from '@/config'
2022-04-24 08:50:45 +00:00
import { uploadService } from '@/services'
import { useUpload } from '@/composables'
2022-04-15 14:24:30 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
2024-03-19 22:48:12 +00:00
import BtnGroup from '@/components/ui/BtnGroup.vue'
2022-04-15 14:24:30 +00:00
const Btn = defineAsyncComponent(() => import('@/components/ui/Btn.vue'))
const UploadItem = defineAsyncComponent(() => import('@/components/ui/upload/UploadItem.vue'))
2022-04-15 17:00:08 +00:00
2022-04-24 08:29:14 +00:00
const acceptAttribute = acceptedMediaTypes.join(',')
2022-04-21 18:39:18 +00:00
const { allowsUpload, mediaPathSetUp, queueFilesForUpload, handleDropEvent } = useUpload()
2022-04-24 08:50:45 +00:00
const files = toRef(uploadService.state, 'files')
2022-04-15 17:00:08 +00:00
const droppable = ref(false)
2024-01-24 22:39:47 +00:00
const hasUploadFailures = computed(() => files.value.filter(({ status }) => status === 'Errored').length > 0)
2022-04-15 17:00:08 +00:00
const onDragEnter = () => (droppable.value = allowsUpload.value)
const onDragLeave = () => (droppable.value = false)
2022-12-02 16:17:37 +00:00
const onFileInputChange = (event: Event) => {
2022-04-15 17:00:08 +00:00
const selectedFileList = (event.target as HTMLInputElement).files
if (selectedFileList?.length) {
queueFilesForUpload(Array.from(selectedFileList))
2022-04-15 17:00:08 +00:00
}
}
const onDrop = async (event: DragEvent) => {
droppable.value = false
await handleDropEvent(event)
2022-04-15 17:00:08 +00:00
}
const retryAll = () => uploadService.retryAll()
const removeFailedEntries = () => uploadService.removeFailed()
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss">
#uploadWrapper {
.upload-panel {
position: relative;
flex: 1;
display: flex;
flex-direction: column;
2022-04-15 14:24:30 +00:00
}
.upload-files {
padding-bottom: 1rem;
}
input[type=file] {
position: absolute;
top: 0;
left: 0;
opacity: 0;
width: 100%;
height: 100%;
z-index: 2;
cursor: pointer;
}
a.or-click {
position: relative;
}
}
</style>