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

Update: Include avatars on list view. #63309

Merged
merged 2 commits into from
Jul 10, 2024
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
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function Author( { item, viewType } ) {
const withIcon = viewType !== LAYOUT_LIST;

return (
<HStack alignment="left" spacing={ 1 }>
<HStack alignment="left" spacing={ 0 }>
{ withIcon && imageUrl && (
<div
className={ clsx( 'page-templates-author-field__avatar', {
Expand Down
9 changes: 4 additions & 5 deletions packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ function Title( { item, viewType } ) {
);
}

function AuthorField( { item, viewType } ) {
function AuthorField( { item } ) {
const [ isImageLoaded, setIsImageLoaded ] = useState( false );
const { text, icon, imageUrl } = useAddedBy( item.type, item.id );
const withIcon = viewType !== LAYOUT_LIST;

return (
<HStack alignment="left" spacing={ 1 }>
{ withIcon && imageUrl && (
<HStack alignment="left" spacing={ 0 }>
{ imageUrl && (
<div
className={ clsx( 'page-templates-author-field__avatar', {
'is-loaded': isImageLoaded,
Expand All @@ -121,7 +120,7 @@ function AuthorField( { item, viewType } ) {
/>
</div>
) }
{ withIcon && ! imageUrl && (
{ ! imageUrl && (
<div className="page-templates-author-field__icon">
<Icon icon={ icon } />
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/edit-site/src/components/page-templates/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
width: $grid-unit-30;
height: $grid-unit-30;
align-items: center;
justify-content: center;
justify-content: left;
display: flex;

img {
width: 20px;
height: 20px;
width: $grid-unit-20;
height: $grid-unit-20;
object-fit: cover;
opacity: 0;
transition: opacity 0.1s linear;
Expand All @@ -94,6 +94,7 @@
height: $grid-unit-30;

svg {
margin-left: -$grid-unit-05;
fill: currentColor;
}
}
Expand Down
24 changes: 8 additions & 16 deletions packages/edit-site/src/components/posts-app/posts-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function PostStatusField( { item } ) {
const label = status?.label || item.status;
const icon = status?.icon;
return (
<HStack alignment="left" spacing={ 1 }>
<HStack alignment="left" spacing={ 0 }>
{ icon && (
<div className="posts-list-page-post-author-field__icon-container">
<Icon icon={ icon } />
Expand All @@ -241,26 +241,22 @@ function PostStatusField( { item } ) {
);
}

function PostAuthorField( { item, viewType } ) {
const { text, icon, imageUrl } = useSelect(
function PostAuthorField( { item } ) {
const { text, 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 (
<HStack alignment="left" spacing={ 1 }>
{ withAuthorImage && (
<HStack alignment="left" spacing={ 0 }>
{ !! imageUrl && (
<div
className={ clsx( 'page-templates-author-field__avatar', {
'is-loaded': isImageLoaded,
Expand All @@ -273,9 +269,9 @@ function PostAuthorField( { item, viewType } ) {
/>
</div>
) }
{ withAuthorIcon && (
{ ! imageUrl && (
<div className="page-templates-author-field__icon">
<Icon icon={ icon } />
<Icon icon={ authorIcon } />
</div>
) }
<span className="page-templates-author-field__name">{ text }</span>
Expand Down Expand Up @@ -471,11 +467,7 @@ export default function PostsList( { postType } ) {
value: id,
label: name,
} ) ) || [],
render: ( { item } ) => {
return (
<PostAuthorField viewType={ view.type } item={ item } />
);
},
render: PostAuthorField,
},
{
header: __( 'Status' ),
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/posts-app/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@

.posts-list-page-post-author-field__icon-container {
height: $grid-unit-30;
width: $grid-unit-30;
svg {
fill: currentColor;
margin-left: -$grid-unit-05;
}
}
Loading