This commit is contained in:
furo 2021-11-14 23:14:42 +01:00
commit 1e5c920c9d
3 changed files with 19 additions and 11 deletions

View File

@ -24,7 +24,7 @@ routes.get(
const maps = wrapper.searchMap(map, categories.split(","), stars.split(","), sort, order, page)
tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps" })
tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps", query: req.query })
}
)

View File

@ -31,18 +31,26 @@
{%- endif -%}
{% endmacro %}
{% macro pager(pageNum, maxPage) %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page=1">1</a>
{% macro pageLink(pageNum, currentPage, queries) %}
{#
Yes! :D
I feel like I have brain damage...
#}
<a class="page {{ "current-page" if currentPage === pageNum }}" href="?{% for query, value in queries %}{{ query if query !== "page" }}{{ "=" if query !== "page" }}{{ value if query !== "page" }}{{ "&" if query !== "page" }}{% endfor %}page={{ pageNum }}">{{ pageNum }}</a>
{% endmacro %}
{% macro pager(pageNum, maxPage, queries) %}
{{ pageLink(1, pageNum, queries) }}
<p>{{ "..." if (pageNum - 2 > 1) }}</p>
{% for page in range(pageNum - 2, pageNum + 3) %}
{% if page > 1 and page < maxPage %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page={{ page }}">{{ page }}</a>
{{ pageLink(page, pageNum, queries) }}
{% endif %}
{% endfor %}
<p>{{ "..." if (pageNum + 2 < maxPage) }}</p>
{% if maxPage > 1 %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page={{ maxPage }}">{{ maxPage }}</a>
{{ pageLink(maxPage, pageNum, queries) }}
{% endif %}
{% endmacro %}

View File

@ -11,17 +11,17 @@
<main class="flex-container">
<form action="/maps" method="get" id="search">
<h1>Search</h1>
<input type="text" name="map" id="map" placeholder="Map name">
<input type="text" name="categories" id="categories" placeholder="Category">
<input type="text" name="stars" id="stars" placeholder="Star amount">
<input type="text" name="map" id="map" placeholder="Map name" value="{{ options.query.map }}">
<input type="text" name="categories" id="categories" placeholder="Category" value="{{ options.query.categories }}">
<input type="text" name="stars" id="stars" placeholder="Star amount" value="{{ options.query.stars }}">
<div class="sorting">
<label for="asc">
<input type="radio" name="order" id="asc" value="asc">
<input type="radio" name="order" id="asc" value="asc" {{ "checked" if options.query.sortyBy == "asc" }}>
Sort Ascending
</label>
<label for="desc">
<input type="radio" name="order" id="desc" value="desc">
<input type="radio" name="order" id="desc" value="desc" {{ "checked" if options.query.sortyBy == "desc" }}>
Sort Descending
</label>
</div>
@ -30,7 +30,7 @@
</form>
<div class="flex-container pages">
{{ utils.pager(data.maps.pageInfo.page, data.maps.pageInfo.totalPages) }}
{{ utils.pager(data.maps.pageInfo.page, data.maps.pageInfo.totalPages, options.query) }}
</div>
{% for map in data.maps.maps %}