From b38afece91d47b0e7e6efdac22b13b7ad68c82f7 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 7 Feb 2023 12:19:00 +0800 Subject: [PATCH] refactor(nc-gui): move logic to useAttachment --- .../components/cell/attachment/index.vue | 23 ++++--------------- .../nc-gui/components/smartsheet/Gallery.vue | 21 ++++------------- .../nc-gui/components/smartsheet/Kanban.vue | 19 ++++----------- 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vue index e8395bc1a0..8a2632b7fa 100644 --- a/packages/nc-gui/components/cell/attachment/index.vue +++ b/packages/nc-gui/components/cell/attachment/index.vue @@ -12,6 +12,7 @@ import { nextTick, openLink, ref, + useAttachment, useDropZone, useSelectedCellKeyupListener, useSmartsheetRowStoreOrThrow, @@ -42,12 +43,12 @@ const attachmentCellRef = ref() const sortableRef = ref() -const { appInfo } = useGlobal() - const currentCellRef = ref(dropZoneInjection.value) const { cellRefs, isSharedForm } = useSmartsheetStoreOrThrow()! +const { getAttachmentSrc, showFallback } = useAttachment() + const { isPublic, isForm, @@ -96,20 +97,6 @@ const { state: rowState } = useSmartsheetRowStoreOrThrow() const { isOverDropZone } = useDropZone(currentCellRef as any, onDrop) -const getImgSrc = (item: Record) => { - if (item.data) { - return item.data - } else if (item.path) { - return `${appInfo.value.ncSiteUrl}/${item.path}` - } - return item.url -} - -const showFallback = (evt: any, item: Record) => { - evt.onerror = null - evt.target.src = item.url -} - /** on new value, reparse our stored attachments */ watch( () => modelValue, @@ -236,14 +223,14 @@ useSelectedCellKeyupListener(inject(ActiveCellInj, ref(false)), (e) => {
{{ item.title }}
-