-
Notifications
You must be signed in to change notification settings - Fork 0
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
load-more component #26
base: review
Are you sure you want to change the base?
Conversation
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.
src/Blocks/components/load-more/load-more-style.scss empty files should be removed
for (let element of elements) { | ||
const url = element.dataset.url; | ||
const containerClass = element.dataset.container; | ||
const button = element.querySelector('button'); |
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.
all js selectors must have .js- prefix
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.
Is .js-load-more load-more__button
ok for a selector?
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.
you should only use .js-load-more
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.
In this case I need to target the button so I can add an event listener to it, though.
.js-load-more
is in the top component div.
@@ -0,0 +1,33 @@ | |||
import domReady from '@wordpress/dom-ready'; |
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.
all js files must be written using dynamic Import for optimisations purposes.
Please refer to the carousel assets or any other assets in the 8shift-frontend-libs or solplanet project
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.
That's exactly how it is in the 8shift-frontend libs Carousel block 😁
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.
Is this the correct way to do it?
async function load() {
let domReady = await import('@wordpress/dom-ready');
domReady.default(() => {
// ...
});
}
load();
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.
Why did you use async await here?
this is allready dynamic import
https://github.com/infinum/eightshift-frontend-libs/blob/c84e4dd0af2ff05cd2cd7bcc62e5e0097c39ed55/blocks/init/src/Blocks/custom/carousel/assets/index.js#L10
read about this:
https://medium.com/front-end-weekly/webpack-and-dynamic-imports-doing-it-right-72549ff49234
https://medium.com/front-end-weekly/webpack-and-dynamic-imports-doing-it-right-72549ff49234
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 use async/await because
let bar = await foo();
// use bar
should be the same as
foo().then((bar) => {
// use bar
});
I like async/await more because it works the same, but removes the unnecessary indentation and brackets.
(same with x.forEach((y) => {})
and for (let y of x) {}
😄 )
But if .then()
is how it's done everywhere, I'll change it to be consistent with everything.
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.
BTW in the Carousel example, domReady
isn't being dynamically imported, right?
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.
We are using webpack dynamic import because then webpack handles when the file is actually loaded in the DOM witch reduces the JS file sizes.
Please use carousel as reference.
No domReady is not dynamically imported
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.
If I understood you correctly, I should move most of the logic into a separate file and then in index.js dynamically import it?
Unlike Carousel, I don't need to import anything external, all of the loading logic is pure async JS.
Should domReady
be dynamically imported or is it ok if it stays like it is in Carousel?
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.
Please just check this other examples and make it like this:
<Fragment> | ||
{loadMoreUse && | ||
<div className={buttonWrapClass}> | ||
<i>{loadMoreButtonLabel}</i> |
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.
thy the tag here?
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.
Should've been p
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.
You dont need any tag here
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 has since been replaced with a RichText to make it changeable live in editor, like the button itself. the button editor.
return ( | ||
<Fragment> | ||
{loadMoreUse && | ||
<div className={buttonWrapClass}> |
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.
if this is a button use button not div. We must follow the correct semantics
@@ -0,0 +1,90 @@ | |||
import React from 'react'; |
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.
please fix this story as I see in the code you dont have nothing similar to this
@@ -0,0 +1,53 @@ | |||
|
|||
async function load() { |
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.
you have overcomplicated this please read the provided docs in the comment and see how Js is done on other blocks and projects
<Fragment> | ||
{loadMoreUse && | ||
<Fragment> | ||
<div style={{ |
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.
never ever ever use inline css
{componentTitle} | ||
</p> | ||
<small><i>{componentDescription}</i></small> | ||
<br /> |
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.
also br for spacing is bit no no
<br /> | ||
<br /> | ||
|
||
<div className="btn-wrap btn-wrap__align--center"> |
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.
why not use button component here if you are using button?*
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.
Guess I could should, I did it like this because I didn't think of any user customization of the button :D
|
||
|
||
{loadMoreUse && | ||
<Fragment> |
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.
indention wrong
/> | ||
<TextControl | ||
label="Starting item index URL parameter" | ||
value={loadMoreStartItemParameterName ?? ''} |
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.
up
<TextControl | ||
label="Starting item index URL parameter" | ||
value={loadMoreStartItemParameterName ?? ''} | ||
onChange={(value) => setAttributes({ [`loadMoreStartItemParameterName`]: value })} |
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.
up
use UnicornsVendor\EightshiftLibs\Helpers\Components; | ||
|
||
$manifest = Components::getManifest(__DIR__); | ||
|
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.
where is use check here?
?> | ||
|
||
<div class="<?php echo \esc_attr($loadMoreClass); ?>" data-url="<?php echo \esc_url_raw($loadMoreUrl); ?>" data-paginated="<?php echo \esc_attr($loadMoreUsePagination); ?>" data-per-page="<?php echo \esc_attr($loadMoreItemsPerPage); ?>" data-per-page-param="<?php echo \esc_attr($loadMoreItemsPerPageParameterName); ?>" data-start-item="<?php echo \esc_attr($loadMoreStartItem); ?>" data-start-item-param="<?php echo \esc_attr($loadMoreStartItemParameterName); ?>"> | ||
<div class="<?php echo \esc_attr($componentJsClass) ?>--container"></div> |
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.
comment in the previous PR
<div class="<?php echo \esc_attr($componentJsClass) ?>--container"></div> | ||
|
||
<?php | ||
echo \wp_kses_post(Components::render('button', array_merge( |
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.
you are using button component here and in JS you didn't
@@ -29,6 +29,7 @@ | |||
$loadMoreItemsPerPageParameterName = Components::checkAttr('loadMoreItemsPerPageParameterName', $attributes, $manifest, $componentName); | |||
$loadMoreStartItem = Components::checkAttr('loadMoreStartItem', $attributes, $manifest, $componentName); | |||
$loadMoreStartItemParameterName = Components::checkAttr('loadMoreStartItemParameterName', $attributes, $manifest, $componentName); | |||
$loadMoreInitialLoad = $attributes['loadMoreInitialLoad'] ?? 'false'; |
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.
use checkAttr functionality here na put this in the manifest
@@ -38,7 +39,7 @@ | |||
|
|||
?> | |||
|
|||
<div class="<?php echo \esc_attr($loadMoreClass); ?>" data-url="<?php echo \esc_url_raw($loadMoreUrl); ?>" data-paginated="<?php echo \esc_attr($loadMoreUsePagination); ?>" data-per-page="<?php echo \esc_attr($loadMoreItemsPerPage); ?>" data-per-page-param="<?php echo \esc_attr($loadMoreItemsPerPageParameterName); ?>" data-start-item="<?php echo \esc_attr($loadMoreStartItem); ?>" data-start-item-param="<?php echo \esc_attr($loadMoreStartItemParameterName); ?>"> | |||
<div class="<?php echo \esc_attr($loadMoreClass); ?>" data-initial-load="<?php echo \esc_attr($loadMoreInitialLoad); ?>" data-url="<?php echo \esc_url_raw($loadMoreUrl); ?>" data-paginated="<?php echo \esc_attr($loadMoreUsePagination); ?>" data-per-page="<?php echo \esc_attr($loadMoreItemsPerPage); ?>" data-per-page-param="<?php echo \esc_attr($loadMoreItemsPerPageParameterName); ?>" data-start-item="<?php echo \esc_attr($loadMoreStartItem); ?>" data-start-item-param="<?php echo \esc_attr($loadMoreStartItemParameterName); ?>"> |
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.
brake this in multiple lines so it is easy to read
} = attributes; | ||
|
||
return ( | ||
<Fragment> |
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.
if you have only one top level item you don't need fragment
] | ||
)); | ||
|
||
$buttonHtml = str_replace("{$componentClass}__button", "{$componentJsClass}-button", $buttonHtml); |
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.
again never do this
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.
Should I fix this with a render_block_data
filter or?
The only other option I can think of is to modify the button to allow passing extra classes.
@@ -0,0 +1,11 @@ | |||
import React from 'react'; |
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.
why do you need load more block?
you are never going to use it as a block. please remove it
{loadMoreUse && | ||
<Fragment> | ||
<div className={`${componentClass}__editor-wrapper`}> | ||
<p className={`${componentClass}__editor-wrapper-title`}> |
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.
what is this title and description? If you have decription for the component put it in the options sidebar
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 wanted to make the block a bit nicer in the editor, but I can remove it.
No description provided.