Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jan 20, 2023
1 parent 4e27883 commit 4b5988e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InspectorControls,
RichText,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
ComboboxControl,
Expand All @@ -22,7 +23,6 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
import { addQueryArgs } from '@wordpress/url';

const minimumUsersForCombobox = 25;

Expand All @@ -36,17 +36,14 @@ const DEFAULT_AVATAR_SIZES = [ 24, 48, 96 ].map( ( size ) => ( {
label: `${ size } x ${ size }`,
} ) );

const DEFAULT_AVATAR_URL =
'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&f=y';

function PostAuthorEdit( {
isSelected,
context: { postType, postId, queryId },
attributes,
setAttributes,
} ) {
const isDescendentOfQueryLoop = Number.isFinite( queryId );
const { authorId, authorDetails, authors } = useSelect(
const { authorId, authorDetails, authors, defaultAutorUrl } = useSelect(
( select ) => {
const { getEditedEntityRecord, getUser, getUsers } =
select( coreStore );
Expand All @@ -55,11 +52,15 @@ function PostAuthorEdit( {
postType,
postId
)?.author;
const { getSettings } = select( blockEditorStore );
const { avatarURL } =
getSettings().__experimentalDiscussionSettings;

return {
authorId: _authorId,
authorDetails: _authorId ? getUser( _authorId ) : null,
authors: getUsers( AUTHORS_QUERY ),
defaultAutorUrl: avatarURL,
};
},
[ postType, postId ]
Expand All @@ -85,9 +86,7 @@ function PostAuthorEdit( {
const authorName = authorDetails?.name || __( 'Post Author' );
const avatarUrl = authorDetails?.avatar_urls
? authorDetails.avatar_urls[ avatarSize ]
: addQueryArgs( DEFAULT_AVATAR_URL, {
s: avatarSize,
} );
: defaultAutorUrl;

const blockProps = useBlockProps( {
className: classnames( {
Expand Down

0 comments on commit 4b5988e

Please sign in to comment.