-
Notifications
You must be signed in to change notification settings - Fork 4.7k
PrePublishPanel: suggest tags and postformat #8235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
151f9e9
4d8af26
1becfb8
ed9753b
dfb60da
870b5e7
7218b33
b0c1464
c98522c
83635bc
0a0cd18
9f53604
ac4e132
f8d386d
ab0bf56
9ef07b3
b2073e8
603c7a1
e40d773
620dbbd
1baa309
053038d
5d18b23
ed42917
52ab3d3
e230479
713d5a6
c1ac898
afffd27
dc3d61a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,26 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { find, get, includes, union } from 'lodash'; | ||
|
|
||
| /** | ||
| * WordPress dependencies. | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { ifCondition, compose } from '@wordpress/compose'; | ||
| import { withSelect } from '@wordpress/data'; | ||
| import { Dashicon, PanelBody } from '@wordpress/components'; | ||
| import { withDispatch, withSelect } from '@wordpress/data'; | ||
| import { Button, Dashicon, PanelBody } from '@wordpress/components'; | ||
|
|
||
| /** | ||
| * Internal dependencies. | ||
| */ | ||
| import PostFormat from '../post-format'; | ||
| import { POST_FORMATS } from '../post-format'; | ||
|
|
||
| const PostFormatSuggested = ( { suggestion, onUpdatePostFormat } ) => <Button isLink onClick={ () => onUpdatePostFormat( suggestion.id ) }> | ||
|
||
| { suggestion.caption } | ||
| </Button>; | ||
|
|
||
| const PostFormatPanel = ( ) => <PanelBody initialOpen={ false } title={ [ | ||
| const PostFormatPanel = ( { suggestion, onUpdatePostFormat } ) => <PanelBody initialOpen={ false } title={ [ | ||
|
||
| <Dashicon | ||
| key={ 'dashicon-lightbulb' } | ||
| icon={ 'lightbulb' } | ||
|
|
@@ -23,16 +32,30 @@ const PostFormatPanel = ( ) => <PanelBody initialOpen={ false } title={ [ | |
| }</span>, | ||
| ] } > | ||
| <p>Post formats are used to display different types of content differently.</p> | ||
| <PostFormat /> | ||
| <p>It looks like you may want to use the <PostFormatSuggested suggestion={ suggestion } onUpdatePostFormat={ onUpdatePostFormat } /> post format type for this post.</p> | ||
| </PanelBody>; | ||
|
|
||
| export default compose( | ||
| withSelect( ( select ) => { | ||
| const { getEditedPostAttribute, getSuggestedPostFormat } = select( 'core/editor' ); | ||
| const suggestedPostFormat = getSuggestedPostFormat(); | ||
| const currentPostFormat = getEditedPostAttribute( 'format' ); | ||
| const themeSupports = select( 'core' ).getThemeSupports(); | ||
| // Ensure current format is always in the set. | ||
| // The current format may not be a format supported by the theme. | ||
| const supportedFormats = union( [ currentPostFormat ], get( themeSupports, [ 'formats' ], [] ) ); | ||
| const formats = POST_FORMATS.filter( ( format ) => includes( supportedFormats, format.id ) ); | ||
| const suggestion = find( formats, ( format ) => format.id === suggestedPostFormat ); | ||
| return { | ||
| suggestedPostFormat: getSuggestedPostFormat(), | ||
| currentPostFormat: getEditedPostAttribute( 'format' ), | ||
| currentPostFormat, | ||
| suggestedPostFormat, | ||
| suggestion, | ||
| }; | ||
| } ), | ||
| withDispatch( ( dispatch ) => ( { | ||
| onUpdatePostFormat( postFormat ) { | ||
| dispatch( 'core/editor' ).editPost( { format: postFormat } ); | ||
| }, | ||
| } ) ), | ||
| ifCondition( ( { suggestedPostFormat, currentPostFormat } ) => suggestedPostFormat && suggestedPostFormat !== currentPostFormat ), | ||
| )( PostFormatPanel ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd to replicate this here when it's likely in the API (single source of truth is good), but I get it's from before your commit. 🤷♂️