// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {IOrderedBlock} from '../blocks/orderedBlock' import {CardTree} from '../viewModel/cardTree' import {OctoUtils} from '../octoUtils' import mutator from '../mutator' import {Utils} from '../utils' import {MutableTextBlock} from '../blocks/textBlock' import Menu from '../widgets/menu' import MenuWrapper from '../widgets/menuWrapper' import {MarkdownEditor} from './markdownEditor' type Props = { block: IOrderedBlock cardId: string cardTree: CardTree } class ContentBlock extends React.Component { shouldComponentUpdate() { return true } public render(): JSX.Element { const {cardId, cardTree, block} = this.props if (block.type !== 'text' && block.type !== 'image') { return null } const index = cardTree.contents.indexOf(block) return (
{index > 0 && { const previousBlock = cardTree.contents[index - 1] const newOrder = OctoUtils.getOrderBefore(previousBlock, cardTree.contents) Utils.log(`moveUp ${newOrder}`) mutator.changeOrder(block, newOrder, 'move up') }} />} {index < (cardTree.contents.length - 1) && { const nextBlock = cardTree.contents[index + 1] const newOrder = OctoUtils.getOrderAfter(nextBlock, cardTree.contents) Utils.log(`moveDown ${newOrder}`) mutator.changeOrder(block, newOrder, 'move down') }} />} { const newBlock = new MutableTextBlock() newBlock.parentId = cardId // TODO: Handle need to reorder all blocks newBlock.order = OctoUtils.getOrderBefore(block, cardTree.contents) Utils.log(`insert block ${block.id}, order: ${block.order}`) mutator.insertBlock(newBlock, 'insert card text') }} /> { Utils.selectLocalFile( (file) => { mutator.createImageBlock(cardId, file, OctoUtils.getOrderBefore(block, cardTree.contents)) }, '.jpg,.jpeg,.png') }} /> mutator.deleteBlock(block)} />
{block.type === 'text' && { Utils.log(`change text ${block.id}, ${text}`) mutator.changeTitle(block, text, 'edit card text') }} />} {block.type === 'image' && {block.title}}
) } } export default ContentBlock