From dfa6eab997e733c9c3b965457ebca7829766e304 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 2 Aug 2022 20:21:54 +0200 Subject: [PATCH] chore(gui-v2): move common functions to attachment cell utils file --- .../components/cell/attachment/Modal.vue | 100 +++++++++++------- .../components/cell/attachment/index.vue | 9 +- .../components/cell/attachment/utils.ts | 15 ++- 3 files changed, 74 insertions(+), 50 deletions(-) diff --git a/packages/nc-gui-v2/components/cell/attachment/Modal.vue b/packages/nc-gui-v2/components/cell/attachment/Modal.vue index 8567cd7bb0..5348ca9b28 100644 --- a/packages/nc-gui-v2/components/cell/attachment/Modal.vue +++ b/packages/nc-gui-v2/components/cell/attachment/Modal.vue @@ -1,30 +1,34 @@ - diff --git a/packages/nc-gui-v2/components/cell/attachment/index.vue b/packages/nc-gui-v2/components/cell/attachment/index.vue index 594558f815..408fd96331 100644 --- a/packages/nc-gui-v2/components/cell/attachment/index.vue +++ b/packages/nc-gui-v2/components/cell/attachment/index.vue @@ -23,7 +23,7 @@ const emits = defineEmits() const dropZoneRef = ref() -const { modalVisible, attachments, visibleItems, onFileSelect, isLoading, open, FileIcon, fileRemovedHook, fileAddedHook } = +const { modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, fileRemovedHook, fileAddedHook } = useProvideAttachmentCell() const { isOverDropZone } = useDropZone(dropZoneRef, onDrop) @@ -46,13 +46,6 @@ fileAddedHook.on((data) => { emits('update:modelValue', data) }) -function onDrop(droppedFiles: File[] | null) { - if (droppedFiles) { - // set files - onFileSelect(droppedFiles) - } -} - const selectImage = (file: any, i: unknown) => { // todo: implement } diff --git a/packages/nc-gui-v2/components/cell/attachment/utils.ts b/packages/nc-gui-v2/components/cell/attachment/utils.ts index c98b0a53d0..5f19130b7f 100644 --- a/packages/nc-gui-v2/components/cell/attachment/utils.ts +++ b/packages/nc-gui-v2/components/cell/attachment/utils.ts @@ -1,4 +1,5 @@ import { notification } from 'ant-design-vue' +import FileSaver from 'file-saver' import { computed, createEventHook, inject, ref, useApi, useFileDialog, useInjectionState, useProject, watch } from '#imports' import { ColumnInj, EditModeInj, MetaInj } from '~/context' import { isImage } from '~/utils' @@ -93,6 +94,17 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(( fileAddedHook.trigger([...attachments.value, ...newAttachments]) } + function onDrop(droppedFiles: File[] | null) { + if (droppedFiles) { + // set files + onFileSelect(droppedFiles) + } + } + + async function downloadFile(item: Record) { + FileSaver.saveAs(item.url || item.data, item.title) + } + const FileIcon = (icon: string) => { switch (icon) { case 'mdi-pdf-box': @@ -125,11 +137,12 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(( isLoading, api, open, - onFileSelect, + onDrop, modalVisible, FileIcon, fileRemovedHook, fileAddedHook, removeFile, + downloadFile, } }, 'attachmentCell')