From 34e5ca8010b8077958ff8682bf1020f5cf7e7bda Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 9 Apr 2018 16:41:34 +0200 Subject: [PATCH] Add shouldComponent to Wysiwyg --- .../lib/src/components/Wysiwyg/index.js | 36 +++++++++++++++++-- .../src/components/Wysiwyg/previewWysiwyg.js | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js index 02ae9090b0..e2d8bf10b8 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js @@ -51,9 +51,9 @@ class Wysiwyg extends React.Component { editorState: EditorState.createEmpty(), isDraging: false, isFocused: false, + isFullscreen: false, isPreviewMode: false, headerValue: '', - isFullscreen: false, }; this.focus = () => { this.setState({ isFocused: true }); @@ -84,6 +84,38 @@ class Wysiwyg extends React.Component { } } + shouldComponentUpdate(nextProps, nextState) { + if (nextState.editorState !== this.state.editorState) { + return true; + } + + if (nextProps.resetProps !== this.props.resetProps) { + return true; + } + + if (nextState.isDraging !== this.state.isDraging) { + return true; + } + + if (nextState.isFocused !== this.state.isFocused) { + return true; + } + + if (nextState.isFullscreen !== this.state.isFullscreen) { + return true; + } + + if (nextState.isPreviewMode !== this.state.isPreviewMode) { + return true; + } + + if (nextState.headerValue !== this.state.headerValue) { + return true; + } + + return false; + } + componentDidUpdate(prevProps) { // Handle resetProps if (prevProps.resetProps !== this.props.resetProps) { @@ -362,7 +394,7 @@ class Wysiwyg extends React.Component { handleDrop = e => { e.preventDefault(); - + console.log('kkks'); if (this.state.isPreviewMode) { return this.setState({ isDraging: false }); } diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js index 27fe03f0de..a0c05f9293 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js @@ -57,7 +57,7 @@ const decorator = new CompositeDecorator([ }, ]); -class PreviewWysiwyg extends React.Component { +class PreviewWysiwyg extends React.PureComponent { state = { editorState: EditorState.createEmpty(), isMounted: false }; componentDidMount() {