From dfdf9d0999bef712582f443129613b0558ca4ca0 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 24 Nov 2017 11:30:15 +0100 Subject: [PATCH] Components: Extract Undo/Redo buttons as reusable components --- editor/components/editor-history/redo.js | 35 +++++++++++++++++++ editor/components/editor-history/undo.js | 35 +++++++++++++++++++ editor/components/index.js | 2 ++ .../edit-post/header/header-toolbar/index.js | 27 ++++---------- 4 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 editor/components/editor-history/redo.js create mode 100644 editor/components/editor-history/undo.js diff --git a/editor/components/editor-history/redo.js b/editor/components/editor-history/redo.js new file mode 100644 index 00000000000000..6aaeeba59bcdfa --- /dev/null +++ b/editor/components/editor-history/redo.js @@ -0,0 +1,35 @@ +/** + * External dependencies + */ +import { connect } from 'react-redux'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { IconButton } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import { hasEditorRedo } from '../../selectors'; + +function EditorHistoryRedo( { hasRedo, redo } ) { + return ( + + ); +} + +export default connect( + ( state ) => ( { + hasRedo: hasEditorRedo( state ), + } ), + ( dispatch ) => ( { + redo: () => dispatch( { type: 'REDO' } ), + } ) +)( EditorHistoryRedo ); diff --git a/editor/components/editor-history/undo.js b/editor/components/editor-history/undo.js new file mode 100644 index 00000000000000..52637f18bb8644 --- /dev/null +++ b/editor/components/editor-history/undo.js @@ -0,0 +1,35 @@ +/** + * External dependencies + */ +import { connect } from 'react-redux'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { IconButton } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import { hasEditorUndo } from '../../selectors'; + +function EditorHistoryUndo( { hasUndo, undo } ) { + return ( + + ); +} + +export default connect( + ( state ) => ( { + hasUndo: hasEditorUndo( state ), + } ), + ( dispatch ) => ( { + undo: () => dispatch( { type: 'UNDO' } ), + } ) +)( EditorHistoryUndo ); diff --git a/editor/components/index.js b/editor/components/index.js index 494f779f6d434f..33d44425a93d65 100644 --- a/editor/components/index.js +++ b/editor/components/index.js @@ -1,6 +1,8 @@ // Post Related Components export { default as AutosaveMonitor } from './autosave-monitor'; export { default as DocumentOutline } from './document-outline'; +export { default as EditorHistoryRedo } from './editor-history/redo'; +export { default as EditorHistoryUndo } from './editor-history/undo'; export { default as MetaBoxes } from './meta-boxes'; export { default as PageAttributes } from './page-attributes'; export { default as PageAttributesCheck } from './page-attributes/check'; diff --git a/editor/edit-post/header/header-toolbar/index.js b/editor/edit-post/header/header-toolbar/index.js index b4db0193746a57..e095fb19721c37 100644 --- a/editor/edit-post/header/header-toolbar/index.js +++ b/editor/edit-post/header/header-toolbar/index.js @@ -7,34 +7,25 @@ import { connect } from 'react-redux'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { IconButton } from '@wordpress/components'; /** * Internal dependencies */ import './style.scss'; -import { Inserter, BlockToolbar, TableOfContents } from '../../../components'; +import { Inserter, BlockToolbar, TableOfContents, EditorHistoryRedo, EditorHistoryUndo } from '../../../components'; import BlockSwitcher from '../../../components/block-switcher'; import NavigableToolbar from '../../../components/navigable-toolbar'; -import { getMultiSelectedBlockUids, hasEditorUndo, hasEditorRedo, isFeatureActive } from '../../../selectors'; +import { getMultiSelectedBlockUids, isFeatureActive } from '../../../selectors'; -function HeaderToolbar( { hasUndo, hasRedo, hasFixedToolbar, undo, redo, isMultiBlockSelection, selectedBlockUids } ) { +function HeaderToolbar( { hasFixedToolbar, isMultiBlockSelection, selectedBlockUids } ) { return ( - - + + { isMultiBlockSelection && (
@@ -53,15 +44,9 @@ export default connect( ( state ) => { const selectedBlockUids = getMultiSelectedBlockUids( state ); return { - hasUndo: hasEditorUndo( state ), - hasRedo: hasEditorRedo( state ), hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ), isMultiBlockSelection: selectedBlockUids.length > 1, selectedBlockUids, }; - }, - ( dispatch ) => ( { - undo: () => dispatch( { type: 'UNDO' } ), - redo: () => dispatch( { type: 'REDO' } ), - } ) + } )( HeaderToolbar );