Skip to content

Conversation

@akasunil
Copy link
Member

@akasunil akasunil commented Mar 2, 2024

What?

Resolves #59222.

Added loader while image is being uploaded in featured image block, Site logo block and cover block. Issue reported in #59222

Why?

Loading state which indicate that image is being uploaded was missing.

Testing Instructions

  1. Add any of below listed block in new post/Site editor
    • Featured image
    • Site logo
    • Cover
  2. Drag and drop image on bock

Screenshots or screencast

CleanShot 2024-03-06 at 19 02 36

@akasunil akasunil requested a review from ajitbohra as a code owner March 2, 2024 09:55
@github-actions
Copy link

github-actions bot commented Mar 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sunil25393 <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: annezazu <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@akasunil akasunil changed the title Add loading state on image upload in featured image block Add loading state on image upload in featured image, Site logo and Cover blocks Mar 6, 2024
@akasunil
Copy link
Member Author

@t-hamano Can you please review this PR ?

@akasunil
Copy link
Member Author

@Mamaduka need your help to review this PR.

@Mamaduka Mamaduka self-requested a review March 29, 2024 13:06
@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Post Featured Image Affects the Post Featured Image Block [Block] Site Logo Affects the Site Logo Block labels Mar 29, 2024
@Mamaduka
Copy link
Member

Mamaduka commented Mar 29, 2024

@sunil25393, I'll try to have a look next week.

Side note: It's usually easier for review to review atomic PRs targeting a single block or feature.

@akasunil
Copy link
Member Author

akasunil commented Apr 3, 2024

Side note: It's usually easier for review to review atomic PRs targeting a single block or feature.

I understand, but since the code is for similar kind of functionality for all three blocks, i included it in single PR.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @sunil25393!

I left a couple of notes based on the initial review.

@@ -1,4 +1,6 @@
.wp-block-cover {
position: relative;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this rule was removed for some reason after the loading state was introduced for the Cover block (#25401).

Let's avoid unexpected regression and only apply this style conditionally. We can put &.is-transient { position: relative; } near other loading state classes (they start at L32).

Comment on lines 70 to 73
// When image being uploaded.
&.is-transient img {
opacity: 0.3;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the &.is-transient::before styles already handle this, so there's no need for image opacity.

Comment on lines 187 to 193
// Reset temporary url when media is available.
useEffect( () => {
if ( media && temporaryURL ) {
setTemporaryURL();
}
}, [ media, temporaryURL ] );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can ditch this effect and reset setTemporaryURL in onSelectImage when the feature image ID is set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the same thing before, however it takes time to set media after calling onSelectImage, and at that time, the placeholder is displayed. It causes flashing. So, I have to clear temporaryURL after media is set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Let's use the derived mediaUrl string value for the condition instead of the media object.


if ( ! media.id && media.url ) {
// This is a temporary blob image.
setTemporaryURL( media?.url );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setTemporaryURL( media?.url );
setTemporaryURL( media.url );

Nit: There's no need for optional chaining here. See the condition above.

return;
}

setTemporaryURL( media?.url );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for setting a temp URL here? The blob URL check above returns early, so the image will be uploaded when this line is reached.

This line causes the Site Logo to be displayed in the upload state when selecting an already uploaded image from the Media Library.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, Must have added to test. forgot to remove it after.

};

const onRemoveLogo = () => {
setTemporaryURL();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also remove the call here. The " Reset " control uses the' onRemoveLogo' callback, which is only displayed after the image upload.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it by removing this, It works fine.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the feedback, @sunil25393!

The changes test well for me ✅

@Mamaduka Mamaduka merged commit d9a6429 into WordPress:trunk Apr 15, 2024
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 15, 2024
@akasunil akasunil deleted the fix-issue-59222 branch April 15, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Post Featured Image Affects the Post Featured Image Block [Block] Site Logo Affects the Site Logo Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Editor: uploading an image in featured image placeholder doesn't show loading state similar to Images

2 participants