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

load-more component #26

Open
wants to merge 40 commits into
base: review
Choose a base branch
from
Open

load-more component #26

wants to merge 40 commits into from

Conversation

goranalkovic-infinum
Copy link
Owner

No description provided.

Copy link
Collaborator

@iruzevic iruzevic left a 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

src/Blocks/components/load-more/assets/index.js Outdated Show resolved Hide resolved
src/Blocks/components/load-more/assets/index.js Outdated Show resolved Hide resolved
for (let element of elements) {
const url = element.dataset.url;
const containerClass = element.dataset.container;
const button = element.querySelector('button');
Copy link
Collaborator

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

Copy link
Owner Author

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?

Copy link
Collaborator

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

Copy link
Owner Author

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';
Copy link
Collaborator

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

Copy link
Owner Author

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 😁

Copy link
Owner Author

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();

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Owner Author

@goranalkovic-infinum goranalkovic-infinum Jan 22, 2021

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.

Copy link
Owner Author

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?

Copy link
Collaborator

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

Copy link
Owner Author

@goranalkovic-infinum goranalkovic-infinum Jan 25, 2021

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?

Copy link
Collaborator

@iruzevic iruzevic Jan 25, 2021

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/assets/index.js Outdated Show resolved Hide resolved
src/Blocks/components/load-more/assets/index.js Outdated Show resolved Hide resolved
<Fragment>
{loadMoreUse &&
<div className={buttonWrapClass}>
<i>{loadMoreButtonLabel}</i>
Copy link
Collaborator

Choose a reason for hiding this comment

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

thy the tag here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Should've been p

Copy link
Collaborator

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

Copy link
Owner Author

@goranalkovic-infinum goranalkovic-infinum Jan 25, 2021

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}>
Copy link
Collaborator

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';
Copy link
Collaborator

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() {
Copy link
Collaborator

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={{
Copy link
Collaborator

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 />
Copy link
Collaborator

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">
Copy link
Collaborator

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?*

Copy link
Owner Author

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>
Copy link
Collaborator

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 ?? ''}
Copy link
Collaborator

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 })}
Copy link
Collaborator

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__);

Copy link
Collaborator

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>
Copy link
Collaborator

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(
Copy link
Collaborator

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';
Copy link
Collaborator

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); ?>">
Copy link
Collaborator

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>
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

again never do this

Copy link
Owner Author

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';
Copy link
Collaborator

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`}>
Copy link
Collaborator

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

Copy link
Owner Author

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.

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.

2 participants