Skip to content

Show more button on home page implementation #3424

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

Closed
wants to merge 8 commits into from
Closed

Show more button on home page implementation #3424

wants to merge 8 commits into from

Conversation

jmuzsik
Copy link

@jmuzsik jmuzsik commented Mar 26, 2018

Hi, in reference to #1303. This is what I did:

pypi_issue_1303

Some things to mention:

  • If you look at the video you'll notice that there is sometimes this gimicky behaviour when I reload quickly. I tried a handful of ways to fix this but think the only real way is inline styling, setting display:none automatically when the package box is created but that is not allowed. This or something can be done in python in which case I have no clue where to even begin.
  • I added this little bit of logic: {% set summary = release.summary if release.summary else "No description provided" %} to get rid of the creation of an empty paragraph element that caused the boxes being even which you'll notice exists in the issue image.
  • Also, let me know if I should delete the if statements in show-more-initial because there will always be more than 20 packages in latest and trending. In the mock database there are sometimes only 19 for trending.
  • Last, basically all these frameworks are new to me so I am not sure if I am doing best practices.

Thanks!

Copy link

@drunkwcodes drunkwcodes left a comment

Choose a reason for hiding this comment

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

I'm wondering where are these buttons at every time while browsing the home page.

LGTM.

@brainwane
Copy link
Contributor

Thank you for the PR, @jmuzsik ! @yeraydiazdiaz , could you review?

Copy link
Contributor

@yeraydiazdiaz yeraydiazdiaz 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 your PR, it really helps the front page. I left a few comments, let me know if you need any clarification.

latestElements[i].style.display = "none";
}
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this logic could live in the Stimulus controller? You could use data-target attributes instead of hide-by-index-* classes which I believe do not add styling and then write a connect method that does the hiding of the last 15 items. The password_controller uses a similar pattern.

Copy link
Author

Choose a reason for hiding this comment

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

Ok I figured out how to use Stimulus properly (I believe). I got rid of any manipulation of the DOM without using Stimulus

@@ -84,35 +97,39 @@ <h1 class="homepage-banner__title">Find, install and publish Python packages wit
</div>
</section>

<section class="horizontal-section horizontal-section--grey">
<div class="site-container">
<section class="horizontal-section horizontal-section--grey" data-controller="increment">
Copy link
Contributor

Choose a reason for hiding this comment

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

increment seems a bit generic to me, show_more might be more applicable?

Copy link
Author

Choose a reason for hiding this comment

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

changed

<div class="col-half">
<div class="heading-wsubtitle">
<h2 class="heading-wsubtitle__heading">Trending Projects</h2>
<p class="heading-wsubtitle__subtitle">Trending projects as downloaded by the community</p>
</div>
<div class="package-list">
<div class="package-list-timeout">
Copy link
Contributor

Choose a reason for hiding this comment

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

what does the -timeout suffix do? I can't find a reference to it

Copy link
Author

Choose a reason for hiding this comment

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

you're right, unnecessary

{% if current.amount_to_show < trending_projects_visible.total %}
{{ project_snippet_trending(release, release.summary, current.amount_to_show) }}
{% set current.amount_to_show = current.amount_to_show + 1 %}
{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this loop might be clearer simply iterating over an index? something like

{% for i in range([trending_projects_visible.total, trending_projects|length]|min) %}
  {{ project_snippet_trending(trending_projects[i], trending_projects[i].summary, i) }}
{% endfor %}

(the range argument is admittedly awkward due to min and length being Jinja2 template filters)

Copy link
Author

Choose a reason for hiding this comment

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

made it much more clear now, actually how it was originally, I did not need all those extra jinga variables

</h3>
<p class="package-snippet__description">{{ release.summary }}</p>
{% set trending_projects_visible = namespace(total=20) %}
{% set latest_releases_visible = namespace(total=20) %}
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need the namespace? seems like it could simply be latest_releases_visible_total = 20

Copy link
Author

Choose a reason for hiding this comment

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

didn't need it at all, logic can be done in Stimulus

{{ project_snippet(release, summary, index)}}
</div>
{%- endmacro %}
{% macro project_snippet_trending(release, summary, index) -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

these two macros differ only on the class, it might be cleaner to move the class to be an extra argument on the project_snippet macro below and just use that one?

Copy link
Author

Choose a reason for hiding this comment

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

Just noticed this, fixed it

static targets = ["button"];

// Initially set default to 5 projects visible
constructor() {
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than constructor Stimulus encourages other methods, in this case I'd opt for connect

constructor() {
super();
this.trending_visible = 5;
this.latest_visible = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be neater and simpler if instead of having the controller wrapping both columns, having one instance of a controller per column, i.e. the <div class="col-half">.

That would make remove all the complexity below on parsing and retrieving the eventType and the separate _visible variables.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, it was hard to read

</div>
{%- endmacro %}

{% macro project_snippet(release, summary, index) -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need summary as an argument? seems you're retrieving it from release or defaulting anyway

Copy link
Author

Choose a reason for hiding this comment

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

Nope, unnecessary, you are right

@jmuzsik
Copy link
Author

jmuzsik commented Mar 31, 2018

Thanks @yeraydiazdiaz! Believe that I have everything as you requested it to be. Definitely appreciated all the advice, definitely improved my ability with Stimulus and Jinga.

Let me know if you'd like anything else to change

Copy link
Contributor

@yeraydiazdiaz yeraydiazdiaz left a comment

Choose a reason for hiding this comment

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

Hey, I left you some more comments, I probably should've explained what I meant better, Stimulus works a bit different than other frameworks I'm also getting used to it as well.

@@ -0,0 +1,42 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need two controllers with the same code, Stimulus makes separate instances of the same class.

{% if class == "latest" %}
<div class="package-snippet" data-target="show-latest-releases.latestRelease">
{% else %}
<div class="package-snippet" data-target="show-trending-projects.trendingProject">
Copy link
Contributor

Choose a reason for hiding this comment

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

if you use a single controller, you can avoid this if completely and use something like data-target="show-more.release"

Copy link
Author

Choose a reason for hiding this comment

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

I don't see how I can do this, show-more.latestReleases and show-more.trendingProjects are entirely different arrays, perhaps there is something clever I can do I don't think there is an explicit way I can do it

<div class="site-container">
<div class="col-half">
<div class="site-container" >
<div class="col-half" data-controller="show-trending-projects">
Copy link
Contributor

Choose a reason for hiding this comment

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

you could simply use data-controller="show-more" here and below, Stimulus will create separate instances

{#
<a class="button" href="TODO">Show More</a>
#}
<button class="button" type="button" data-action="click->show-trending-projects#addFive" data-target="show-trending-projects.addFiveButton">Show More</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

remember to change the names on these, there won't be clashing as they're separate DOM elements and instances

<div class="heading-wsubtitle">
<h2 class="heading-wsubtitle__heading">New Releases</h2>
<p class="heading-wsubtitle__subtitle">Hot off the press: the newest project releases</p>
</div>
<div class="package-list">
{% for release in latest_releases %}
{{ project_snippet(release) }}
{{ project_snippet(release, "latest") }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can even remove the class parameter?

Copy link
Author

Choose a reason for hiding this comment

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

not sure if that is possible, as I mentioned above

connect() {
this.amountVisible = 5;
let i = 0;
for (let element of this.latestReleaseTargets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be more compact to use some Array constructs:

this.releaseTargets.slice(this.amountVisible).forEach(element => {
  element.style.display = "none";
});

@di di self-assigned this Apr 2, 2018
@yeraydiazdiaz
Copy link
Contributor

Sorry, what I meant was something like e7befb8

The key is adding two data-controller instances, one per column, instead of a general one for both.

It might sound odd because we're using the same names for the targets but they're local to each data-controller so no clashing occurs. The benefit is that the controller is much simpler and will work on any number of columns.

@jmuzsik
Copy link
Author

jmuzsik commented Apr 4, 2018

You are definitely right, I did not know that I could do this, but you basically wrote the entire PR based upon that code you wrote there. So perhaps you ought to send the PR? I mean if you want to I can close this and you can send it instead.

Either way, I'll put the working copy up. Thanks so much @yeraydiazdiaz!

Copy link
Contributor

@yeraydiazdiaz yeraydiazdiaz left a comment

Choose a reason for hiding this comment

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

now that's just silly 😄 nice work on this 👍

@yeraydiazdiaz
Copy link
Contributor

yeraydiazdiaz commented Apr 13, 2018

@jmuzsik up for resolving the conflicts and bringing this one home? 😄

@jmuzsik
Copy link
Author

jmuzsik commented Apr 14, 2018

I didn't realise there were any! Thanks!

@nlhkabu nlhkabu self-assigned this Apr 17, 2018
@nlhkabu
Copy link
Contributor

nlhkabu commented Apr 17, 2018

hi @jmuzsik thanks for this PR and thanks also to @yeraydiazdiaz for your reviews :)
Just to let you know - this is on my list of things to pull down and review this week - sorry for the delay and thanks for your patience!

Copy link
Contributor

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

I find it a little awkward that elements get added to the section, in place.

I think it would be more intuitive (to me) to be redirected to a search that shows results in the same order?

@di
Copy link
Member

di commented Apr 17, 2018

I think generally I'm in agreement with @pradyunsg. This also depends heavily on JS and won't work at all for users without JS or not in a modern browser, whereas linking to an ordered search result page would. I'll let have @nlhkabu have the final say here though.

@nlhkabu
Copy link
Contributor

nlhkabu commented Apr 23, 2018

I agree with @pradyunsg and @di on this. If we were instead to direct the user to an ordered search results page, they could also apply search filters, which would give them more options. They would also benefit from any improvements we make to the search UI in the future.

@jmuzsik Is this something that you'd like to take on?

I have updated #1303 and #3447 accordingly.

@jmuzsik
Copy link
Author

jmuzsik commented Apr 23, 2018

It makes complete sense to do it as you guys have spoken of, though I cannot do it right now, I would say in a few weeks I can begin to but I really am not sure. But if anyone else would like to take it on, by all means, maybe @yeraydiazdiaz. Thanks!

@nlhkabu
Copy link
Contributor

nlhkabu commented Apr 25, 2018

ok great @jmuzsik :) Are you happy to close this PR in the meantime?

@jmuzsik jmuzsik closed this Apr 30, 2018
@brainwane
Copy link
Contributor

@jmuzsik Thank you for your work on this. Please do let us know if you want thoughts on stuff to take on when you're more ready, in a few weeks!

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.

7 participants