-
Notifications
You must be signed in to change notification settings - Fork 1k
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
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.
I'm wondering where are these buttons at every time while browsing the home page.
LGTM.
Thank you for the PR, @jmuzsik ! @yeraydiazdiaz , could you review? |
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.
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"; | ||
} | ||
} | ||
}; |
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.
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.
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.
Ok I figured out how to use Stimulus properly (I believe). I got rid of any manipulation of the DOM without using Stimulus
warehouse/templates/index.html
Outdated
@@ -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"> |
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.
increment
seems a bit generic to me, show_more
might be more applicable?
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.
changed
warehouse/templates/index.html
Outdated
<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"> |
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 does the -timeout
suffix do? I can't find a reference to it
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're right, unnecessary
warehouse/templates/index.html
Outdated
{% 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 %} |
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 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)
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.
made it much more clear now, actually how it was originally, I did not need all those extra jinga variables
warehouse/templates/index.html
Outdated
</h3> | ||
<p class="package-snippet__description">{{ release.summary }}</p> | ||
{% set trending_projects_visible = namespace(total=20) %} | ||
{% set latest_releases_visible = namespace(total=20) %} |
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.
do you need the namespace
? seems like it could simply be latest_releases_visible_total = 20
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.
didn't need it at all, logic can be done in Stimulus
warehouse/templates/index.html
Outdated
{{ project_snippet(release, summary, index)}} | ||
</div> | ||
{%- endmacro %} | ||
{% macro project_snippet_trending(release, summary, index) -%} |
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.
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?
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.
Just noticed this, fixed it
static targets = ["button"]; | ||
|
||
// Initially set default to 5 projects visible | ||
constructor() { |
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.
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; |
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 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.
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're right, it was hard to read
warehouse/templates/index.html
Outdated
</div> | ||
{%- endmacro %} | ||
|
||
{% macro project_snippet(release, summary, index) -%} |
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.
do you need summary
as an argument? seems you're retrieving it from release
or defaulting anyway
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.
Nope, unnecessary, you are right
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 |
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.
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 @@ | |||
/** |
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 don't need two controllers with the same code, Stimulus makes separate instances of the same class.
warehouse/templates/index.html
Outdated
{% if class == "latest" %} | ||
<div class="package-snippet" data-target="show-latest-releases.latestRelease"> | ||
{% else %} | ||
<div class="package-snippet" data-target="show-trending-projects.trendingProject"> |
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 use a single controller, you can avoid this if
completely and use something like data-target="show-more.release"
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 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
warehouse/templates/index.html
Outdated
<div class="site-container"> | ||
<div class="col-half"> | ||
<div class="site-container" > | ||
<div class="col-half" data-controller="show-trending-projects"> |
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 could simply use data-controller="show-more"
here and below, Stimulus will create separate instances
warehouse/templates/index.html
Outdated
{# | ||
<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> |
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.
remember to change the names on these, there won't be clashing as they're separate DOM elements and instances
warehouse/templates/index.html
Outdated
<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") }} |
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 think you can even remove the class parameter?
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.
not sure if that is possible, as I mentioned above
connect() { | ||
this.amountVisible = 5; | ||
let i = 0; | ||
for (let element of this.latestReleaseTargets) { |
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 might be more compact to use some Array
constructs:
this.releaseTargets.slice(this.amountVisible).forEach(element => {
element.style.display = "none";
});
Sorry, what I meant was something like e7befb8 The key is adding two It might sound odd because we're using the same names for the targets but they're local to each |
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! |
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.
now that's just silly 😄 nice work on this 👍
@jmuzsik up for resolving the conflicts and bringing this one home? 😄 |
I didn't realise there were any! Thanks! |
hi @jmuzsik thanks for this PR and thanks also to @yeraydiazdiaz for your reviews :) |
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 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?
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. |
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? |
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! |
ok great @jmuzsik :) Are you happy to close this PR in the meantime? |
@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! |
Hi, in reference to #1303. This is what I did:
Some things to mention:
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.{% 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.Thanks!