cleanup handler interface

This commit is contained in:
Chen-I Lim 2021-03-10 15:03:26 -08:00
parent 13d63f9cd1
commit 42d7bc9a88
4 changed files with 1 additions and 61 deletions

View file

@ -13,7 +13,6 @@ type ContentHandler = {
getDisplayText: (intl: IntlShape) => string,
getIcon: () => JSX.Element,
createBlock: () => Promise<MutableContentBlock>,
addBlock(card: Card, contents: readonly IContentBlock[], index: number, intl: IntlShape): void,
createComponent: (block: IContentBlock, intl: IntlShape, readonly: boolean) => JSX.Element,
}

View file

@ -3,7 +3,6 @@
import React from 'react'
import {MutableDividerBlock} from '../../blocks/dividerBlock'
import mutator from '../../mutator'
import DividerIcon from '../../widgets/icons/divider'
import {contentRegistry} from './contentRegistry'
@ -22,20 +21,6 @@ contentRegistry.registerContentType({
createBlock: async () => {
return new MutableDividerBlock()
},
addBlock: (card, contents, index, intl) => {
const newBlock = new MutableDividerBlock()
newBlock.parentId = card.id
newBlock.rootId = card.rootId
const contentOrder = contents.map((o) => o.id)
contentOrder.splice(index, 0, newBlock.id)
const typeName = intl.formatMessage({id: 'ContentBlock.divider', defaultMessage: 'divider'})
mutator.performAsUndoGroup(async () => {
const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName})
await mutator.insertBlock(newBlock, description)
await mutator.changeCardContentOrder(card, contentOrder, description)
})
},
createComponent: () => <DividerElement/>,
})

View file

@ -3,9 +3,8 @@
import React from 'react'
import {injectIntl, IntlShape} from 'react-intl'
import {IContentBlock, MutableContentBlock} from '../../blocks/contentBlock'
import {IContentBlock} from '../../blocks/contentBlock'
import {MutableImageBlock} from '../../blocks/imageBlock'
import mutator from '../../mutator'
import octoClient from '../../octoClient'
import {Utils} from '../../utils'
import ImageIcon from '../../widgets/icons/image'
@ -72,21 +71,6 @@ contentRegistry.registerContentType({
// return new MutableImageBlock()
},
addBlock: (card, contents, index, intl) => {
Utils.selectLocalFile((file) => {
mutator.performAsUndoGroup(async () => {
const typeName = intl.formatMessage({id: 'ContentBlock.image', defaultMessage: 'image'})
const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName})
const newBlock = await mutator.createImageBlock(card, file, description)
if (newBlock) {
const contentOrder = contents.map((o) => o.id)
contentOrder.splice(index, 0, newBlock.id)
await mutator.changeCardContentOrder(card, contentOrder, description)
}
})
},
'.jpg,.jpeg,.png')
},
createComponent: (block, intl) => {
return (
<ImageElement

View file

@ -18,20 +18,6 @@ type Props = {
}
class TextElement extends React.PureComponent<Props> {
readonly type = 'text'
createBlock(): MutableContentBlock {
return new MutableTextBlock()
}
getDisplayText(intl: IntlShape): string {
return intl.formatMessage({id: 'ContentBlock.text', defaultMessage: 'text'})
}
getIcon(): JSX.Element {
return <TextIcon/>
}
render(): JSX.Element {
const {intl, block, readonly} = this.props
@ -55,20 +41,6 @@ contentRegistry.registerContentType({
createBlock: async () => {
return new MutableTextBlock()
},
addBlock: (card, contents, index, intl) => {
const newBlock = new MutableTextBlock()
newBlock.parentId = card.id
newBlock.rootId = card.rootId
const contentOrder = contents.map((o) => o.id)
contentOrder.splice(index, 0, newBlock.id)
const typeName = intl.formatMessage({id: 'ContentBlock.text', defaultMessage: 'text'})
mutator.performAsUndoGroup(async () => {
const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName})
await mutator.insertBlock(newBlock, description)
await mutator.changeCardContentOrder(card, contentOrder, description)
})
},
createComponent: (block, intl, readonly) => {
return (
<TextElement