From 51921453ee90a3ffdd47e95e6c7bdc9fd003c6ff Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 9 Jul 2024 11:33:51 +0200 Subject: [PATCH] Updated: Pages: Include avatar in Author field. (#63142) Co-authored-by: jorgefilipecosta Co-authored-by: carolinan Co-authored-by: ntsekouras Co-authored-by: youknowriad Co-authored-by: jameskoster Co-authored-by: ellatrix --- .../src/components/posts-app/posts-list.js | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/posts-app/posts-list.js b/packages/edit-site/src/components/posts-app/posts-list.js index cf9b6f43ef9cf1..c4ee0301730928 100644 --- a/packages/edit-site/src/components/posts-app/posts-list.js +++ b/packages/edit-site/src/components/posts-app/posts-list.js @@ -1,7 +1,16 @@ +/** + * External dependencies + */ +import clsx from 'clsx'; + /** * WordPress dependencies */ -import { Button, __experimentalHStack as HStack } from '@wordpress/components'; +import { + Button, + __experimentalHStack as HStack, + Icon, +} from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; import { decodeEntities } from '@wordpress/html-entities'; @@ -17,6 +26,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; import { useSelect, useDispatch } from '@wordpress/data'; import { DataViews } from '@wordpress/dataviews'; import { privateApis as editorPrivateApis } from '@wordpress/editor'; +import { commentAuthorAvatar as authorIcon } from '@wordpress/icons'; /** * Internal dependencies @@ -207,6 +217,48 @@ function getItemId( item ) { return item.id.toString(); } +function PostAuthorField( { item, viewType } ) { + const { text, icon, imageUrl } = useSelect( + ( select ) => { + const { getUser } = select( coreStore ); + const user = getUser( item.author ); + return { + icon: authorIcon, + imageUrl: user?.avatar_urls?.[ 48 ], + text: user?.name, + }; + }, + [ item ] + ); + + const withAuthorImage = viewType !== LAYOUT_LIST && imageUrl; + const withAuthorIcon = viewType !== LAYOUT_LIST && ! imageUrl; + const [ isImageLoaded, setIsImageLoaded ] = useState( false ); + return ( + + { withAuthorImage && ( +
+ setIsImageLoaded( true ) } + alt={ __( 'Author avatar' ) } + src={ imageUrl } + /> +
+ ) } + { withAuthorIcon && ( +
+ +
+ ) } + { text } +
+ ); +} + export default function PostsList( { postType } ) { const [ view, setView ] = useView( postType ); const history = useHistory(); @@ -395,6 +447,11 @@ export default function PostsList( { postType } ) { value: id, label: name, } ) ) || [], + render: ( { item } ) => { + return ( + + ); + }, }, { header: __( 'Status' ),