diff --git a/css/main.css b/css/main.css index 43c4a467..9a25a17a 100644 --- a/css/main.css +++ b/css/main.css @@ -122,3 +122,34 @@ color: var(--color-error); } + +/* File drag and drop */ + +.filesListDragDropNotice{ + display: flex; + align-items: center; + justify-content: center; + width: 100%; + min-height: 113px; + margin: 0; + user-select: none; + color: var(--color-text-maxcontrast); + background-color: var(--color-main-background); + border-color: #000; +} + +.filesListDragDropNoticeWrapper{ + display: flex; + align-items: center; + justify-content: center; + height: 15vh; + max-height: 70%; + padding: 0 5vw; + border: 2px var(--color-border-dark) dashed; + border-radius: var(--border-radius-large); +} + +.filesListDragDropNoticeTitle{ + margin-left: 16px; + color: inherit; +} diff --git a/src/composables/UseFileSelection.js b/src/composables/UseFileSelection.js new file mode 100644 index 00000000..69b79672 --- /dev/null +++ b/src/composables/UseFileSelection.js @@ -0,0 +1,95 @@ +import { useDropZone, useFileDialog } from '@vueuse/core' +import { ref, computed } from 'vue' +import { publicationStore } from './../store/store.js' + +/** + * File selection composable + * @param options + * + * Special thanks to Github user adamreisnz for creating most of this file + * https://github.com/adamreisnz + * https://github.com/vueuse/vueuse/issues/4085 + * + */ +export function useFileSelection(options) { + + // Extract options + const { + dropzone, + allowMultiple, + allowedFileTypes, + onFileDrop, + } = options + + // Data types computed ref + const dataTypes = computed(() => { + if (allowedFileTypes?.value) { + if (!Array.isArray(allowedFileTypes.value)) { + return [allowedFileTypes.value] + } + return allowedFileTypes.value + } + return null + }) + + // Accept string computed ref + const accept = computed(() => { + if (Array.isArray(dataTypes.value)) { + return dataTypes.value.join(',') + } + return '*' + }) + + // Handling of files drop + const onDrop = files => { + if (!files || files.length === 0) { + return + } + if (files instanceof FileList) { + files = Array.from(files) + } + if (files.length > 1 && !allowMultiple.value) { + files = [files[0]] + } + filesList.value = files + onFileDrop && onFileDrop() + } + + const reset = () => { + filesList.value = null + } + + // const onLeave = () => { + // let timer + // document.addEventListener('mousemove', () => { + // clearTimeout(timer) + // timer = setTimeout(isOverDropZone.value = false, 300) + // }) + // } + + const setFiles = (files) => { + filesList.value = files + publicationStore.setAttachmentFile(null) + } + + // Setup dropzone and file dialog composables + const { isOverDropZone } = useDropZone(dropzone, { dataTypes, onDrop }) + const { onChange, open } = useFileDialog({ + accept: accept.value, + multiple: allowMultiple?.value, + }) + + const filesList = ref(null) + + // Use onChange handler + onChange(fileList => onDrop(fileList)) + + // Expose interface + return { + isOverDropZone, + openFileUpload: open, + files: filesList, + reset, + setFiles, + } +} diff --git a/src/modals/Modals.vue b/src/modals/Modals.vue index 224a7064..e3422dd1 100644 --- a/src/modals/Modals.vue +++ b/src/modals/Modals.vue @@ -1,7 +1,11 @@ + + - + diff --git a/src/modals/attachment/AddAttachmentModal.vue b/src/modals/attachment/AddAttachmentModal.vue index 0f4fc0fc..619cb6bb 100644 --- a/src/modals/attachment/AddAttachmentModal.vue +++ b/src/modals/attachment/AddAttachmentModal.vue @@ -7,72 +7,84 @@ import { navigationStore, publicationStore } from '../../store/store.js' ref="modalRef" label-id="AddAttachmentModal" @close="navigationStore.setModal(false)"> - + Bijlage toevoegen - - - Bijlage succesvol toegevoegd - - - Er is iets fout gegaan bij het toevoegen van bijlage - - - {{ error }} - - - - - - - - - - - - - - Bestand toevoegen - - - + + + Bijlage succesvol toegevoegd + + + Er is iets fout gegaan bij het toevoegen van bijlage + + + {{ error }} + + + + + + + + + + + + + + Bestand toevoegen + + + + + + + {{ file.name }} + + + + @click="addAttachment()"> - + + - {{ file.name }} + Toevoegen - - - - - - Toevoegen - + + + + + + + Drag and drop files here to upload + + + @@ -80,14 +92,18 @@ import { navigationStore, publicationStore } from '../../store/store.js' @@ -205,9 +207,20 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from Geen eigenschappen gevonden - + + + + + + + + Drag and drop files here to upload + + + + - + Geen bijlagen gevonden @@ -280,6 +293,7 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from appearance="dark" name="Bijlagen aan het laden" /> + @@ -347,6 +361,7 @@ import { catalogiStore, metadataStore, navigationStore, publicationStore } from diff --git a/tsconfig.json b/tsconfig.json index 773fdce7..959331fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,6 @@ "@/*": ["src/*"] }, }, - "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"], + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "src/composables/UseFileSelection.js"], "exclude": ["node_modules"] } \ No newline at end of file
Bijlage succesvol toegevoegd
Er is iets fout gegaan bij het toevoegen van bijlage
{{ error }}