-
Notifications
You must be signed in to change notification settings - Fork 384
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
Encourage lighter images and videos #2509
Conversation
Do this on the componentDidUpdate method, as it seems that this is where it is updated. Also, revert a change to webpack.config.js that I accidentally staged before.
This is only used on one place, so it is probably better in that class.
Make sure this new image size is used for background image. |
Sure, I'll work on that now. |
Use the newly added 'amp_story_page' image size for the AMP Story background image.
const sizesWithoutFullSize = initialSizes.filter( ( size ) => 'full' !== size.slug ); | ||
|
||
// If the AMP Story slug isn't present, add it. | ||
if ( ! sizesWithoutFullSize.filter( ( size ) => MAX_IMAGE_SIZE_SLUG === size.slug ).length ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if this logic to add the image size didn't have to run so often. For example, if it ran only on wp.domReady()
.
But it looks like the settings update, so these settings will be overwritten if this logic only runs on wp.domReady()
.
…ably need a better solution There was an error: 447:16 error 'select' is already declared in the upper scope no-shadow
Use the 'image_size_names_choose' filter to make the custom image size available in the media const in amp-story-page/edit.js This prevents making a second request for it.
Also, this enables changing the paramter ownSelect to select.
This is the first iteration, and it might need more information in the notice.
Current Display For Large Video Sizes bd8d73b adds a notice on selecting a video as the Background Media if it has more than 1 MB per second, like more than 5 MB for a 5-second video.
To test this, you could download this image, which is 33 seconds and 252 MB. This should display the notice. |
assets/src/stories-editor/components/higher-order/with-replaced-full-size-image.js
Outdated
Show resolved
Hide resolved
@kienstra I'm getting an error: |
Instead of an initial let assignemnt and an if block, this simply assigns it all in one line. Also, simplify reduceRight to reduce. The order doesn't seem to matter, so it doesn't have to be from the right.
As Weston mentioned, it will still work with a large video.
As Weston suggested, the megabytesInBytes constnt can also be used in the admin notice.
As Weston suggested, it's a little less repetetive not having 'AMP' in the name.
If the 'full' size image is never needed in AMP stories, this could be much simpler. It's removed whenever the 'post_type' is 'amp_story'. This might need more thought, though.
Also, on clicking 'Remove Video,' set that attribute back to undefined.
add_new_max_image_size() actually applies to core Image blocks also.
Use this image size if it's available, otherwise simply default to the full size image.
Before, this didn't work with just the filter for 'image_size_names_choose' so get the correct image size after the actual image is chosen.
The filter didn't have access to the post type, so it would run on posts and pages, needlessly adding the 'amp_story_page' custom size. This approach isn't ideal either, but it won't run outside of AMP stories.
It was defined in the entire module, though also used as a parameter of withSelect(). This isn't ideal, but select() is needed to get the image size.
This seems to help with an issue where getMedia() didn't get the background image before.
I couldn't figure out how to enable a custom size for the background image with purely JS. This won't apply to Image blocks in a non-story editor, like for posts.
Hi @westonruter, 0bd76bc#diff-37ed1ba86eaee9e72c2ced620309452bR1545 adds a conditional in the PHP filter to check that This allows it to apply to the background image, but not to the Image block's 'Image Size' I also brought back the JS filter, like earlier in this PR, which replaces the Image block's This time, it didn't see the |
Hi @swissspidy, Would you be available to review this again? Thanks, Pascal! |
@kienstra I'm getting a JS error upon loading the editor: |
Nice, great idea: fb29ca8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is happening here:
Where Component
is the extended BlockEdit
class:
Based on my limited knowledge of React, I was thinking something like this is needed:
--- a/assets/src/stories-editor/components/higher-order/with-replaced-full-size-image.js
+++ b/assets/src/stories-editor/components/higher-order/with-replaced-full-size-image.js
@@ -19,7 +19,7 @@ const BLOCK_EDITOR_STORE = 'core/block-editor';
export default createHigherOrderComponent(
( BlockEdit ) => {
- return class extends BlockEdit {
+ class BlockEditWithReplacedFullImageSize extends BlockEdit {
/**
* The class constructor.
*/
@@ -67,7 +67,9 @@ export default createHigherOrderComponent(
dispatch( BLOCK_EDITOR_STORE ).updateSettings( { imageSizes: sizesWithoutFullSize } );
}
}
- };
+ }
+
+ return ( props ) => <BlockEditWithReplacedFullImageSize { ...props } />;
},
'withReplacedFullSizeImage'
);
But that's not making any change. Perhaps its just syntactic sugar for the exact same thing.
} | ||
|
||
if ( super.componentDidUpdate ) { | ||
super.componentDidUpdate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no React expert, but shouldn't this be passing the args passed into componentDidUpdate
? In other words:
super.componentDidUpdate( ...arguments );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point.
I don't see any other example in the codebase of |
Good point, inheritance isn't a best practice in React, it seems. The only issue is that this needs to 'hook' into the Image edit component's But if this extended it with a higher-order-component, the HOC probably wouldn't call its Maybe there's another approach, though. |
I'll keep looking at this. |
The JS filter produced a console error. So instead, use the existing PHP filter that Weston had suggested.
Hi @westonruter, Does c330ce7 work for you? It uses the PHP filter that you had suggested originally. It works for me locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does work!
{ | ||
sprintf( | ||
/* translators: %d: the number of recommended megabytes per second */ | ||
__( 'A video size of less than %d MB per second is recommended.', 'amp' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing but it would be useful to know how many MB/second the selected video is, to know how far from the target the video is.
@westonruter, thanks a lot for your help and patience! |
'full'
image size with a custom size of99999px
(unlimited) by1440px
Closes #2332