Fix multiattachment (#2950)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-11 23:14:51 +06:00 committed by GitHub
parent f42d06cfce
commit 92d8e3e6df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -137,8 +137,8 @@
newAttachments.add(_id)
attachments = attachments
saved = false
dispatch('attached', _id)
saveDraft()
dispatch('attached', _id)
} catch (err: any) {
setPlatformStatus(unknownError(err))
}
@ -146,6 +146,7 @@
async function saveAttachment (doc: Attachment, objectId: Ref<Doc> | undefined): Promise<void> {
if (space === undefined || objectId === undefined || _class === undefined) return
newAttachments.delete(doc._id)
await client.addCollection(attachment.class.Attachment, space, objectId, _class, 'attachments', doc, doc._id)
}
@ -172,12 +173,13 @@
async function removeAttachment (attachment: Attachment): Promise<void> {
removedAttachments.add(attachment)
attachments.delete(attachment._id)
dispatch('detached', attachment._id)
attachments = attachments
saveDraft()
dispatch('detached', attachment._id)
}
async function deleteAttachment (attachment: Attachment): Promise<void> {
removedAttachments.delete(attachment)
if (originalAttachments.has(attachment._id)) {
await client.removeCollection(
attachment._class,
@ -218,6 +220,20 @@
}
}
export async function saveNewAttachment (_id: Ref<Attachment>): Promise<void> {
const attachment = attachments.get(_id)
if (attachment !== undefined) {
await saveAttachment(attachment, objectId)
}
}
export async function removeAttachmentById (_id: Ref<Attachment>): Promise<void> {
const attachment = attachments.get(_id)
if (attachment !== undefined) {
await removeAttachment(attachment)
}
}
export async function createAttachments (_id: Ref<Doc> | undefined = objectId): Promise<void> {
if (saved) {
return

View File

@ -185,8 +185,8 @@
_class={tracker.class.Issue}
space={issue.space}
alwaysEdit
on:attached={save}
on:detached={save}
on:attached={(e) => descriptionBox.saveNewAttachment(e.detail)}
on:detached={(e) => descriptionBox.removeAttachmentById(e.detail)}
showButtons
on:blur={save}
on:changeContent={triggerSave}