From ccba85bf2775a43685c9aef0e41aca6649d1f289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 31 Mar 2021 12:32:52 +0200 Subject: [PATCH] Migrating contentBlock to functional component --- webapp/src/components/contentBlock.tsx | 136 ++++++++++++------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/webapp/src/components/contentBlock.tsx b/webapp/src/components/contentBlock.tsx index 45a5f7806..73fc1e331 100644 --- a/webapp/src/components/contentBlock.tsx +++ b/webapp/src/components/contentBlock.tsx @@ -30,79 +30,77 @@ type Props = { intl: IntlShape } -class ContentBlock extends React.PureComponent { - public render(): JSX.Element | null { - const {intl, card, contents, block, readonly} = this.props +const ContentBlock = React.memo((props: Props): JSX.Element => { + const {intl, card, contents, block, readonly} = props - const index = contents.indexOf(block) - return ( -
-
- {!this.props.readonly && - - }/> - - {index > 0 && - } - onClick={() => { - const contentOrder = contents.map((o) => o.id) - Utils.arrayMove(contentOrder, index, index - 1) - mutator.changeCardContentOrder(card, contentOrder) - }} - />} - {index < (contents.length - 1) && - } - onClick={() => { - const contentOrder = contents.map((o) => o.id) - Utils.arrayMove(contentOrder, index, index + 1) - mutator.changeCardContentOrder(card, contentOrder) - }} - />} - } - > - {contentRegistry.contentTypes.map((type) => ( - - ))} - + const index = contents.indexOf(block) + return ( +
+
+ {!props.readonly && + + }/> + + {index > 0 && } - id='delete' - name={intl.formatMessage({id: 'ContentBlock.Delete', defaultMessage: 'Delete'})} + id='moveUp' + name={intl.formatMessage({id: 'ContentBlock.moveUp', defaultMessage: 'Move up'})} + icon={} onClick={() => { - const description = intl.formatMessage({id: 'ContentBlock.DeleteAction', defaultMessage: 'delete'}) - const contentOrder = contents.map((o) => o.id).filter((o) => o !== block.id) - mutator.performAsUndoGroup(async () => { - await mutator.deleteBlock(block, description) - await mutator.changeCardContentOrder(card, contentOrder, description) - }) + const contentOrder = contents.map((o) => o.id) + Utils.arrayMove(contentOrder, index, index - 1) + mutator.changeCardContentOrder(card, contentOrder) }} - /> - - - } -
- + />} + {index < (contents.length - 1) && + } + onClick={() => { + const contentOrder = contents.map((o) => o.id) + Utils.arrayMove(contentOrder, index, index + 1) + mutator.changeCardContentOrder(card, contentOrder) + }} + />} + } + > + {contentRegistry.contentTypes.map((type) => ( + + ))} + + } + id='delete' + name={intl.formatMessage({id: 'ContentBlock.Delete', defaultMessage: 'Delete'})} + onClick={() => { + const description = intl.formatMessage({id: 'ContentBlock.DeleteAction', defaultMessage: 'delete'}) + const contentOrder = contents.map((o) => o.id).filter((o) => o !== block.id) + mutator.performAsUndoGroup(async () => { + await mutator.deleteBlock(block, description) + await mutator.changeCardContentOrder(card, contentOrder, description) + }) + }} + /> +
+
+ }
- ) - } -} + +
+ ) +}) export default injectIntl(ContentBlock)