diff --git a/plugins/attachment-resources/src/components/Attachments.svelte b/plugins/attachment-resources/src/components/Attachments.svelte index 3670bfa50c7..d7da3c3bc0c 100644 --- a/plugins/attachment-resources/src/components/Attachments.svelte +++ b/plugins/attachment-resources/src/components/Attachments.svelte @@ -17,11 +17,13 @@ import { Attachment } from '@hcengineering/attachment' import { Class, Data, Doc, DocumentQuery, Ref, Space } from '@hcengineering/core' import { IntlString } from '@hcengineering/platform' - import { Icon, Label, resizeObserver, Scroller, Spinner } from '@hcengineering/ui' + import { Icon, Label, resizeObserver, Scroller, Spinner, Button, IconAdd } from '@hcengineering/ui' import view, { BuildModelKey } from '@hcengineering/view' import { Table } from '@hcengineering/view-resources' + import { getClient } from '@hcengineering/presentation' import attachment from '../plugin' - import AddAttachment from './AddAttachment.svelte' + import { createAttachments } from '../utils' + import { createEventDispatcher } from 'svelte' import AttachmentDroppable from './AttachmentDroppable.svelte' import IconAttachments from './icons/Attachments.svelte' import UploadDuo from './icons/UploadDuo.svelte' @@ -42,37 +44,67 @@ let loading = 0 let dragover = false let wSection: number + + const client = getClient() + const dispatch = createEventDispatcher() + + async function fileSelected () { + const list = inputFile.files + if (list === null || list.length === 0) return + + loading++ + try { + await createAttachments( + client, + list, + { objectClass: _class, objectId, space }, + attachmentClass, + attachmentClassOptions + ) + } finally { + loading-- + } + + if (inputFile) { + inputFile.value = '' + } + + dispatch('attached') + } + + function openFile () { + inputFile.click() + }