Fixing Adding content bug (#1799)

This commit is contained in:
Jesús Espino 2021-11-11 22:59:15 +01:00 committed by GitHub
parent 60f0f5d5c4
commit beee6f53e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 16 deletions

View file

@ -41,11 +41,11 @@ const AddContentMenuItem = React.memo((props:Props): JSX.Element => {
newBlock.parentId = card.id
newBlock.rootId = card.rootId
contentOrder.splice(index, 0, newBlock.id)
const typeName = handler.getDisplayText(intl)
const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName})
mutator.performAsUndoGroup(async () => {
await mutator.insertBlock(newBlock, description)
const insertedBlock = await mutator.insertBlock(newBlock, description)
contentOrder.splice(index, 0, insertedBlock.id)
await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description)
})
}}

View file

@ -29,11 +29,11 @@ function addTextBlock(card: Card, intl: IntlShape, text: string): void {
block.rootId = card.rootId
block.title = text
const contentOrder = card.fields.contentOrder.slice()
contentOrder.push(block.id)
mutator.performAsUndoGroup(async () => {
const description = intl.formatMessage({id: 'CardDetail.addCardText', defaultMessage: 'add card text'})
await mutator.insertBlock(block, description)
const insertedBlock = await mutator.insertBlock(block, description)
const contentOrder = card.fields.contentOrder.slice()
contentOrder.push(insertedBlock.id)
await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description)
})
}

View file

@ -50,16 +50,16 @@ export const CardDetailProvider = (props: CardDetailProps): ReactElement => {
const block = await handler.createBlock(card.rootId)
block.parentId = card.id
block.rootId = card.rootId
const contentOrder = card.fields.contentOrder.slice()
contentOrder.splice(index, 0, block.id)
setLastAddedBlock({
id: block.id,
autoAdded: auto,
})
const typeName = handler.getDisplayText(intl)
const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName})
await mutator.performAsUndoGroup(async () => {
await mutator.insertBlock(block, description)
const insertedBlock = await mutator.insertBlock(block, description)
const contentOrder = card.fields.contentOrder.slice()
contentOrder.splice(index, 0, insertedBlock.id)
setLastAddedBlock({
id: insertedBlock.id,
autoAdded: auto,
})
await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description)
})
},

View file

@ -36,11 +36,11 @@ export default function useImagePaste(cardId: string, contentOrder: Array<string
blocksToInsert.push(block)
}
const newContentOrder = JSON.parse(JSON.stringify(contentOrder))
newContentOrder.push(...blocksToInsert.map((b: ImageBlock) => b.id))
mutator.performAsUndoGroup(async () => {
await mutator.insertBlocks(blocksToInsert, 'pasted images')
const newContentBlocks = await mutator.insertBlocks(blocksToInsert, 'pasted images')
const newContentOrder = JSON.parse(JSON.stringify(contentOrder))
newContentOrder.push(...newContentBlocks.map((b: ImageBlock) => b.id))
await mutator.changeCardContentOrder(cardId, contentOrder, newContentOrder, 'paste image')
})
}, [cardId, contentOrder, rootId])