-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit Post: Move initial edits handling to post editor component
- Loading branch information
Showing
2 changed files
with
69 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,76 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { EditorProvider, ErrorBoundary } from '@wordpress/editor'; | ||
import { StrictMode } from '@wordpress/element'; | ||
import { StrictMode, Component } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Layout from './components/layout'; | ||
|
||
function Editor( { | ||
settings, | ||
hasFixedToolbar, | ||
focusMode, | ||
post, | ||
onError, | ||
...props | ||
} ) { | ||
if ( ! post ) { | ||
return null; | ||
class Editor extends Component { | ||
constructor( props ) { | ||
super( ...arguments ); | ||
|
||
const { initialEdits, editPost } = props; | ||
if ( initialEdits ) { | ||
editPost( initialEdits, { quiet: true } ); | ||
} | ||
} | ||
|
||
const editorSettings = { | ||
...settings, | ||
hasFixedToolbar, | ||
focusMode, | ||
}; | ||
|
||
return ( | ||
<StrictMode> | ||
<EditorProvider | ||
settings={ editorSettings } | ||
post={ post } | ||
{ ...props } | ||
> | ||
<ErrorBoundary onError={ onError }> | ||
<Layout /> | ||
</ErrorBoundary> | ||
</EditorProvider> | ||
</StrictMode> | ||
); | ||
render() { | ||
const { | ||
settings, | ||
hasFixedToolbar, | ||
focusMode, | ||
post, | ||
onError, | ||
...props | ||
} = this.props; | ||
|
||
if ( ! post ) { | ||
return null; | ||
} | ||
|
||
const editorSettings = { | ||
...settings, | ||
hasFixedToolbar, | ||
focusMode, | ||
}; | ||
|
||
return ( | ||
<StrictMode> | ||
<EditorProvider | ||
settings={ editorSettings } | ||
post={ post } | ||
{ ...props } | ||
> | ||
<ErrorBoundary onError={ onError }> | ||
<Layout /> | ||
</ErrorBoundary> | ||
</EditorProvider> | ||
</StrictMode> | ||
); | ||
} | ||
} | ||
|
||
export default withSelect( ( select, { postId, postType } ) => ( { | ||
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ), | ||
focusMode: select( 'core/edit-post' ).isFeatureActive( 'focusMode' ), | ||
post: select( 'core' ).getEntityRecord( 'postType', postType, postId ), | ||
} ) )( Editor ); | ||
export default compose( [ | ||
withSelect( ( select, { postId, postType } ) => { | ||
const { isFeatureActive } = select( 'core/edit-post' ); | ||
const { getEntityRecord } = select( 'core' ); | ||
|
||
return { | ||
hasFixedToolbar: isFeatureActive( 'fixedToolbar' ), | ||
focusMode: isFeatureActive( 'focusMode' ), | ||
post: getEntityRecord( 'postType', postType, postId ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
const { editPost } = dispatch( 'core/editor' ); | ||
|
||
return { editPost }; | ||
} ), | ||
] )( Editor ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters