fix image paste messing with content stuffz (#1075)

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Hossein 2021-08-24 09:20:24 -04:00 committed by GitHub
parent e4e1f2d94a
commit 8de9ec8234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,11 @@ export default function useImagePaste(cardId: string, contentOrder: Array<string
const uploadItems = useCallback(async (items: FileList) => { const uploadItems = useCallback(async (items: FileList) => {
let newImage: File|null = null let newImage: File|null = null
const uploads: Promise<string|undefined>[] = [] const uploads: Promise<string|undefined>[] = []
if (!items.length) {
return
}
for (const item of items) { for (const item of items) {
newImage = item newImage = item
if (newImage?.type.indexOf('image/') === 0) { if (newImage?.type.indexOf('image/') === 0) {
@ -30,10 +35,13 @@ export default function useImagePaste(cardId: string, contentOrder: Array<string
block.fields.fileId = fileId || '' block.fields.fileId = fileId || ''
blocksToInsert.push(block) blocksToInsert.push(block)
} }
const newContentOrder = JSON.parse(JSON.stringify(contentOrder))
newContentOrder.push(...blocksToInsert.map((b: ImageBlock) => b.id))
mutator.performAsUndoGroup(async () => { mutator.performAsUndoGroup(async () => {
await mutator.insertBlocks(blocksToInsert, 'pasted images') await mutator.insertBlocks(blocksToInsert, 'pasted images')
const newContentOrder = [...contentOrder, ...blocksToInsert.map((b: ImageBlock) => b.id)] await mutator.changeCardContentOrder(cardId, contentOrder, newContentOrder, 'paste image')
return mutator.changeCardContentOrder(cardId, contentOrder, newContentOrder, 'paste image')
}) })
}, [cardId, contentOrder, rootId]) }, [cardId, contentOrder, rootId])
@ -58,5 +66,5 @@ export default function useImagePaste(cardId: string, contentOrder: Array<string
document.removeEventListener('paste', onPaste) document.removeEventListener('paste', onPaste)
document.removeEventListener('drop', onDrop) document.removeEventListener('drop', onDrop)
} }
}, []) }, [uploadItems])
} }