Skip to content

Commit

Permalink
Adding back the optimisation introduced in #160
Browse files Browse the repository at this point in the history
  • Loading branch information
Eimi Okuno authored and Eimi Okuno committed Sep 17, 2019
1 parent ff3e3e0 commit 07b905b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
21 changes: 21 additions & 0 deletions packages/components/timed-text-editor/MemoEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

import {
Editor,
} from 'draft-js';

const MemoEditor = (props) => {

return (
<Editor data-testid="memo-editor"
editorState={ props.editorState }
onChange={ props.onChange }
stripPastedStyles
blockRendererFn={ props.renderBlockWithTimecodes }
handleKeyCommand={ props.handleKeyCommand }
keyBindingFn={ props.customKeyBindingFn }
spellCheck={ props.spellCheck }
/>);
};

export default React.memo(MemoEditor);
17 changes: 8 additions & 9 deletions packages/components/timed-text-editor/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import WrapperBlock from './WrapperBlock';

import MemoEditor from './MemoEditor';
import {
Editor,
EditorState,
CompositeDecorator,
convertFromRaw,
Expand Down Expand Up @@ -37,7 +36,6 @@ class TimedTextEditor extends React.Component {

shouldComponentUpdate = (nextProps, nextState) => {
if (nextProps !== this.props) return true;

if (nextState !== this.state ) return true;

return false;
Expand All @@ -46,7 +44,7 @@ class TimedTextEditor extends React.Component {
componentDidUpdate(prevProps, prevState) {
if (
(prevProps.transcriptData !== this.props.transcriptData)
&& ( this.props.mediaUrl !== null && !this.isPresentInLocalStorage(this.props.mediaUrl) )
&& ( this.props.mediaUrl && !this.isPresentInLocalStorage(this.props.mediaUrl) )
) {
this.loadData();
}
Expand Down Expand Up @@ -553,12 +551,13 @@ class TimedTextEditor extends React.Component {
{`span.Word[data-prev-times~="${ time }"] { color: ${ unplayedColor } }`}
{`span.Word[data-confidence="low"] { border-bottom: ${ correctionBorder } }`}
</style>
<Editor data-testid="custom-editor"

<MemoEditor data-testid="memo-editor"
editorState={ this.state.editorState }
onChange={ (e) => this.onChange(e) }
onChange={ this.onChange }
stripPastedStyles
blockRendererFn={ this.renderBlockWithTimecodes }
handleKeyCommand={ (e) => this.handleKeyCommand(e) }
handleKeyCommand={ this.handleKeyCommand }
keyBindingFn={ this.customKeyBindingFn }
spellCheck={ this.props.spellCheck }
/>
Expand All @@ -568,7 +567,7 @@ class TimedTextEditor extends React.Component {

return (
<section >
{ this.props.transcriptData !== null ? editor : null }
{ this.props.transcriptData ? editor : null }
</section>
);
}
Expand All @@ -579,7 +578,7 @@ class TimedTextEditor extends React.Component {
const getEntityStrategy = mutability => (contentBlock, callback, contentState) => {
contentBlock.findEntityRanges((character) => {
const entityKey = character.getEntity();
if (entityKey === null) {
if (!entityKey) {
return false;
}

Expand Down

0 comments on commit 07b905b

Please sign in to comment.