Skip to content

Commit

Permalink
Fix tile add menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Jul 23, 2018
1 parent 9f7be35 commit 770823f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
* Fix view name class in body element @sneridagh @davilima6
* Refactor actions @robgietema
* Store text tile data in json @robgietema
* Fixed tile add menu @robgietema

## 0.6.0 (2018-07-14)

Expand Down
43 changes: 26 additions & 17 deletions src/components/manage/Tiles/Text/Edit.jsx
Expand Up @@ -13,6 +13,7 @@ import createInlineToolbarPlugin from 'draft-js-inline-toolbar-plugin';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import { Icon } from '../../../../components';
import trashSVG from '../../../../icons/delete.svg';
import { isEqual } from 'lodash';

import {
extendedBlockRenderMap,
Expand Down Expand Up @@ -136,11 +137,18 @@ export default class Edit extends Component {
* @returns {undefined}
*/
onChange(editorState) {
if (
!isEqual(
convertToRaw(editorState.getCurrentContent()),
convertToRaw(this.state.editorState.getCurrentContent()),
)
) {
this.props.onChangeTile(this.props.tile, {
...this.props.data,
text: convertToRaw(editorState.getCurrentContent()),
});
}
this.setState({ editorState });
this.props.onChangeTile(this.props.tile, {
...this.props.data,
text: convertToRaw(editorState.getCurrentContent()),
});
}

toggleAddNewTile = () =>
Expand Down Expand Up @@ -209,19 +217,20 @@ export default class Edit extends Component {
/>
<InlineToolbar />

{this.props.data.text &&
this.props.data.text.blocks &&
this.props.data.text.blocks.length === 1 &&
this.props.data.text.blocks[0].text === '' && (
<Button
basic
icon
onClick={this.toggleAddNewTile}
className="tile-add-button"
>
<Icon name={addSVG} className="tile-add-button" size="24px" />
</Button>
)}
{(!this.props.data.text ||
(this.props.data.text &&
this.props.data.text.blocks &&
this.props.data.text.blocks.length === 1 &&
this.props.data.text.blocks[0].text === '')) && (
<Button
basic
icon
onClick={this.toggleAddNewTile}
className="tile-add-button"
>
<Icon name={addSVG} className="tile-add-button" size="24px" />
</Button>
)}
{this.state.addNewTileOpened && (
<div className="add-tile toolbar">
<Button.Group>
Expand Down
9 changes: 5 additions & 4 deletions src/components/manage/Tiles/Tile/Edit.jsx
Expand Up @@ -121,10 +121,11 @@ export default class Edit extends Component {

const hideHandler =
this.props.data['@type'] === 'text' &&
this.props.data.text &&
this.props.data.text.blocks &&
this.props.data.text.blocks.length === 1 &&
this.props.data.text.blocks[0].text === '';
(!this.props.data.text ||
(this.props.data.text &&
this.props.data.text.blocks &&
this.props.data.text.blocks.length === 1 &&
this.props.data.text.blocks[0].text === ''));

const imageAlign =
this.props.data['@type'] === 'image' &&
Expand Down

0 comments on commit 770823f

Please sign in to comment.