Skip to content

Conversation

@StevenDufresne
Copy link
Contributor

@StevenDufresne StevenDufresne commented Jul 20, 2022

This block was created to add pattern previews to the theme directory in this Pull Request.

Block Summary:

  • Loads a visual card container
  • Requests thumbnail from mShots service
  • If the thumbnail is cached in the service, convert to base64, show image.
  • If not, wait, re-request until the thumbnail is ready from mShots service.

@ryelle
Copy link
Contributor

ryelle commented Jul 20, 2022

Rather than create an entire new project (config files, package.json, etc), could you try out the build process & template I proposed in #211 & WordPress/wporg-repo-tools#21?

@StevenDufresne
Copy link
Contributor Author

Yep makes sense. This block was created in a galaxy far far away...I didn't know it would end up here :)

@StevenDufresne
Copy link
Contributor Author

I would like to get this out as a beta on .org, so I'll merge this now and follow up later. If there are any issues, I'll follow them up asap.

@StevenDufresne StevenDufresne merged commit 33bf064 into trunk Jul 20, 2022
@StevenDufresne StevenDufresne deleted the add/screenshot-preview branch July 20, 2022 23:57
@@ -0,0 +1,84 @@
<?php
/**
* Plugin name: Gutenberg: Pattern Previewer
Copy link
Contributor

@adamwoodnz adamwoodnz Jul 22, 2022

Choose a reason for hiding this comment

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

There's a bit of inconsistency between the naming and description here and in block.json. This file is quite particular about it being for previewing patterns, whereas block.json seems more generic. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, just missed this. Nice catch.

* License: GPLv2 or later
*/

namespace WordPressdotorg\Gutenberg\ScreenshotPreview;
Copy link
Contributor

Choose a reason for hiding this comment

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

Gutenberg -> MU_Plugins ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Yes!

window.addEventListener( 'resize', handleOnResize );

return () => {
window.addEventListener( 'resize', handleOnResize );
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is intended to clean up should it be using removeEventListener?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch!

style={ {
height: frameHeight,
} }
tabIndex="-1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to stop keyboard navigation? If so why?

"license": "ISC",
"devDependencies": {
"@wordpress/scripts": "^23.4.0",
"lodash": "^4.17.21"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be in dependencies

/**
* WordPress dependencies
*/
import { useEffect, useState } from '@wordpress/element';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this package in package.json dependencies

return;
}

for ( let i = 0; i < blockElements.length; i++ ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to use forEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the arguments for using forEach?

Copy link
Contributor

@adamwoodnz adamwoodnz Jul 22, 2022

Choose a reason for hiding this comment

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

This pretty much sums it up https://stackoverflow.com/questions/43031988/javascript-efficiency-for-vs-foreach#answer-43032526

Personally as a dev I much prefer to write and read less code. I don't think the perf benefit with a for loop outweighs this in most cases. I tend to stick to all the modern native array functions: forEach, map, some, reduce

Comment on lines +4 to +6
import { __ } from '@wordpress/i18n';
import { useEffect, useRef, useState } from '@wordpress/element';
import { Spinner } from '@wordpress/components';
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing from package.json dependencies?

Copy link
Contributor

@adamwoodnz adamwoodnz left a comment

Choose a reason for hiding this comment

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

Nice work, this is a cool block!

A few minor comments/questions inline, I may be missing some context/know-how though, if so sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants