-
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.
Components: Extract PostFormatCheck component to avoid duplication
- Loading branch information
1 parent
be143b0
commit 24f6cb7
Showing
3 changed files
with
79 additions
and
71 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { get, flowRight } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withAPIData } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getCurrentPostType } from '../selectors'; | ||
|
||
function PostFormatCheck( { postType, children } ) { | ||
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default flowRight( [ | ||
connect( | ||
( state ) => { | ||
return { | ||
postTypeSlug: getCurrentPostType( state ), | ||
}; | ||
}, | ||
), | ||
withAPIData( ( props ) => { | ||
const { postTypeSlug } = props; | ||
|
||
return { | ||
postType: `/wp/v2/types/${ postTypeSlug }?context=edit`, | ||
}; | ||
} ), | ||
] )( PostFormatCheck ); |
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
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,45 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { get, flowRight } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { PanelRow, withAPIData } from '@wordpress/components'; | ||
import { PanelRow } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostFormatSelector from '../../post-format'; | ||
import { getCurrentPostType } from '../../selectors'; | ||
|
||
function PostFormat( { postType } ) { | ||
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) { | ||
return null; | ||
} | ||
import PostFormatCheck from '../../post-format/check'; | ||
import PostFormatForm from '../../post-format'; | ||
|
||
export function PostFormat() { | ||
return ( | ||
<PanelRow> | ||
<PostFormatSelector /> | ||
</PanelRow> | ||
<PostFormatCheck> | ||
<PanelRow> | ||
<PostFormatForm /> | ||
</PanelRow> | ||
</PostFormatCheck> | ||
); | ||
} | ||
|
||
export default flowRight( [ | ||
connect( | ||
( state ) => { | ||
return { | ||
postTypeSlug: getCurrentPostType( state ), | ||
}; | ||
}, | ||
), | ||
withAPIData( ( props ) => { | ||
const { postTypeSlug } = props; | ||
|
||
return { | ||
postType: `/wp/v2/types/${ postTypeSlug }?context=edit`, | ||
}; | ||
} ), | ||
] )( PostFormat ); | ||
export default PostFormat; |