Skip to content
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

Site Editor: Add the featured image panel #57053

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions packages/edit-post/src/components/sidebar/featured-image/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { store as interfaceStore } from '@wordpress/interface';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import {
store as editorStore,
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
} from '@wordpress/editor';
Expand All @@ -22,7 +23,6 @@ import {
*/
import SettingsHeader from '../settings-header';
import PostStatus from '../post-status';
import FeaturedImage from '../featured-image';
import PostExcerpt from '../post-excerpt';
import DiscussionPanel from '../discussion-panel';
import PageAttributes from '../page-attributes';
Expand Down Expand Up @@ -83,7 +83,7 @@ const SidebarContent = ( {
<PluginDocumentSettingPanel.Slot />
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<FeaturedImage />
<PostFeaturedImagePanel />
<PostExcerpt />
<DiscussionPanel />
<PageAttributes />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import {
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
store as editorStore,
Expand Down Expand Up @@ -100,6 +101,7 @@ export default function PagePanels() {
) }
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<PostFeaturedImagePanel />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import { useSelect } from '@wordpress/data';
import { PanelBody } from '@wordpress/components';
import {
PostTaxonomiesPanel,
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
store as editorStore,
} from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -64,6 +65,7 @@ export default function TemplatePanel() {
</PanelBody>
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<PostFeaturedImagePanel />
</>
);
}
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { default as PostExcerpt } from './post-excerpt';
export { default as PostExcerptCheck } from './post-excerpt/check';
export { default as PostFeaturedImage } from './post-featured-image';
export { default as PostFeaturedImageCheck } from './post-featured-image/check';
export { default as PostFeaturedImagePanel } from './post-featured-image/panel';
export { default as PostFormat } from './post-format';
export { default as PostFormatCheck } from './post-format/check';
export { default as PostLastRevision } from './post-last-revision';
Expand Down
55 changes: 55 additions & 0 deletions packages/editor/src/components/post-featured-image/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import PostFeaturedImage from './index';
import PostFeaturedImageCheck from './check';

const PANEL_NAME = 'featured-image';

function FeaturedImage() {
const { postType, isEnabled, isOpened } = useSelect( ( select ) => {
const {
getEditedPostAttribute,
isEditorPanelEnabled,
isEditorPanelOpened,
} = select( editorStore );
const { getPostType } = select( coreStore );

return {
postType: getPostType( getEditedPostAttribute( 'type' ) ),
isEnabled: isEditorPanelEnabled( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
};
}, [] );

const { toggleEditorPanelOpened } = useDispatch( editorStore );

if ( ! isEnabled ) {
return null;
}

return (
<PostFeaturedImageCheck>
<PanelBody
title={
postType?.labels?.featured_image ?? __( 'Featured image' )
}
opened={ isOpened }
onToggle={ () => toggleEditorPanelOpened( PANEL_NAME ) }
>
<PostFeaturedImage />
</PanelBody>
</PostFeaturedImageCheck>
);
}

export default FeaturedImage;
Loading