diff --git a/app/components/ui/file-upload/FileUpload.vue b/app/components/ui/file-upload/FileUpload.vue index b0d9ac0..3462b2e 100644 --- a/app/components/ui/file-upload/FileUpload.vue +++ b/app/components/ui/file-upload/FileUpload.vue @@ -4,11 +4,13 @@ import { Motion } from "motion-v"; import { ref } from "vue"; import { X } from "lucide-vue-next"; import Button from "../button/Button.vue"; +import Progress from "../progress/Progress.vue"; interface FileUploadProps { class?: HTMLAttributes["class"]; accept?: string; modelValue?: File[]; + ongoingUploads?: Map; } const props = defineProps(); @@ -49,12 +51,43 @@ function handleDrop(e: DragEvent) { const droppedFiles = e.dataTransfer?.files ? Array.from(e.dataTransfer.files) : []; if (droppedFiles.length) handleFileChange(droppedFiles); } + function removeFile(event: MouseEvent, index: number) { files.value.splice(index, 1); event.stopPropagation(); emit("update:modelValue", files.value); } +function getUploadProgress(file: File): number { + if (!props.ongoingUploads) return 0; + + for (const [_, upload] of props.ongoingUploads) { + if ( + upload.file.name === file.name && + upload.file.size === file.size && + upload.file.lastModified === file.lastModified + ) { + return upload.progress; + } + } + return 0; +} + +function isFileUploading(file: File): boolean { + if (!props.ongoingUploads) return false; + + for (const [_, upload] of props.ongoingUploads) { + if ( + upload.file.name === file.name && + upload.file.size === file.size && + upload.file.lastModified === file.lastModified + ) { + return true; + } + } + return false; +} + watch(() => props.modelValue, (newVal) => { if (newVal) { files.value = newVal; @@ -68,7 +101,7 @@ watch(() => props.modelValue, (newVal) => { @drop.prevent="handleDrop" @mouseover="handleEnter" @mouseleave="handleLeave">
- +
props.modelValue, (newVal) => {
-
+
+ class="relative z-40 mx-auto flex w-full flex-col items-start justify-start overflow-hidden rounded-md p-4 shadow-sm text-muted-foreground bg-background gap-2">
{{ file.name }} - - {{ (file.size / (1024 * 1024)).toFixed(2) }} MB - +
+ + {{ (file.size / (1024 * 1024)).toFixed(2) }} MB + + + + Uploading... + + +
+ class="flex w-full flex-col items-start justify-between text-sm text-muted-foreground md:flex-row md:items-center"> {{ file.type || "unknown type" }} - -
+
+ +
- + @@ -113,8 +179,12 @@ onUnmounted(() => { Uploaded files
+ + - + +