-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💻 Make the public adventures infinite scroll
The public adventures page had a pagination mechanism, with "next page"/"prev page" buttons. A more modern idiom these days is to use "infinite scroll": once the user scrolls to the bottom of the container, we fetch the next bit of results, and so on.
- Loading branch information
Showing
4 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions
70
templates/public-adventures/incl-adventure-list-elements.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{## | ||
# List the adventure elements, with infinite scroll | ||
# | ||
# | ||
#} | ||
{% for adventure in adventures %} | ||
<div | ||
class="adventure-item text-gray-800 flex flex-col cursor-pointer p-2 border-b border-gray-300" | ||
tabindex="0" | ||
_="on click remove .selected from .adventure-item then add .selected to me end on keyup[key is 'Enter'] send click to me" | ||
hx-get="/public-adventures/preview/{{ adventure.id }}" hx-target="#preview-div" | ||
> | ||
<div class="flex-1"> | ||
<span class="text-xl min-h-28">{{ adventure.name }}</span> | ||
</div> | ||
{# | ||
<div alt="This adventure has been cloned {{ adventure.cloned_times }} times"> | ||
{{ adventure.cloned_stars }} | ||
{{ adventure.cloned_times }} | ||
{% for x in range(adventure.cloned_stars) %} | ||
<span class="fa fa-star text-green-500"></span> | ||
{% endfor %} | ||
</div> | ||
#} | ||
<div class="flex-none text-xs"> | ||
<div class="flex"> | ||
<div class="flex-1 text-gray-500">{{ adventure.creator }}</div> | ||
<div> | ||
<span class="flex-1 text-gray-500" title="{{ adventure.date|jsts_to_unix|datetimeformat }}"> | ||
{{ adventure.date|jsts_to_unix|format_date_rel }} | ||
</span> | ||
</div> | ||
</div> | ||
<div class="flex flex-row"> | ||
<div class="flex-1 text-gray-500">{{_('level')}} {{ adventure.levels|join(', ') }}</div> | ||
<div class="flex-none"> | ||
{% if adventure.solution_example %} | ||
<span class="fa fa-book text-gray-500" title="{{_('this_adventure_has_an_example_solution')}}"></span> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% if adventure.tags %} | ||
<div> | ||
{% for tag in adventure.tags %} | ||
<span class="inline-block bg-pink-200 rounded-full px-2 text-xs text-gray-700 mr-1 mb-1">{{ tag }}</span> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
|
||
{# Infinite scroll token #} | ||
{% if next_page_token %} | ||
<div | ||
hx-get="/public-adventures/more" | ||
hx-trigger="intersect once" | ||
hx-swap="outerHTML" | ||
hx-include="this"> | ||
|
||
<input type="hidden" name="selected_lang" value="{{selected_lang}}"> | ||
<input type="hidden" name="selected_level" value="{{selected_level}}"> | ||
<input type="hidden" name="q" value="{{q}}"> | ||
<input type="hidden" name="selected_tag" value="{{selected_tag}}"> | ||
<input type="hidden" name="page" value="{{next_page_token}}"> | ||
|
||
<img src="{{static('/images/spinner.gif')}}" width="50" class="m-auto py-4"> | ||
|
||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters