Skip to content

Commit

Permalink
Allow multiple files to be selected/dropped at once
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed May 21, 2024
1 parent 6d286aa commit 3696284
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions frontend/src/components/file/FileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,33 @@ const onFileUploadDragAndDrop = (event: FileUploadUploaderEvent) => {
return;
}
onUpload(Array.isArray(event.files) ? event.files[0] : event.files);
onUpload(Array.isArray(event.files) ? event.files : [event.files]);
};
const onUpload = async (file: File) => {
try {
const response = (await documentService.createDocument(file, props.activityId, getConfig.value.coms.bucketId))
?.data;
if (response) {
submissionStore.addDocument(response);
toast.success('Document uploaded');
}
} catch (e: any) {
toast.error('Failed to upload document', e);
}
const onUpload = async (files: Array<File>) => {
await Promise.allSettled(
files.map(async (file: File) => {
try {
const response = (await documentService.createDocument(file, props.activityId, getConfig.value.coms.bucketId))
?.data;
if (response) {
submissionStore.addDocument(response);
toast.success('Document uploaded');
}
} catch (e: any) {
toast.error('Failed to upload document', e);
}
})
);
};
</script>

<template>
<div class="hover-hand hover-shadow">
<FileUpload
name="fileUpload"
:multiple="false"
:multiple="true"
:custom-upload="true"
:auto="true"
:disabled="props.disabled"
Expand Down Expand Up @@ -100,7 +104,8 @@ const onUpload = async (file: File) => {
type="file"
style="display: none"
accept="*"
@change="(event: any) => onUpload(event.target.files[0])"
multiple
@change="(event: any) => onUpload(Array.from(event.target.files))"
@click="(event: any) => (event.target.value = null)"
/>
</div>
Expand Down

0 comments on commit 3696284

Please sign in to comment.