Searching works better now... :D

This commit is contained in:
BurnyLlama 2021-11-13 21:28:28 +01:00
parent 9ca85455af
commit a71172aec3
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) 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 -%} {%- endif -%}
{% endmacro %} {% endmacro %}
{% macro pager(pageNum, maxPage) %} {% macro pageLink(pageNum, currentPage, queries) %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page=1">1</a> {#
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> <p>{{ "..." if (pageNum - 2 > 1) }}</p>
{% for page in range(pageNum - 2, pageNum + 3) %} {% for page in range(pageNum - 2, pageNum + 3) %}
{% if page > 1 and page < maxPage %} {% if page > 1 and page < maxPage %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page={{ page }}">{{ page }}</a> {{ pageLink(page, pageNum, queries) }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<p>{{ "..." if (pageNum + 2 < maxPage) }}</p> <p>{{ "..." if (pageNum + 2 < maxPage) }}</p>
{% if maxPage > 1 %} {% if maxPage > 1 %}
<a class="page {{ "current-page" if page === pageNum }}" href="?page={{ maxPage }}">{{ maxPage }}</a> {{ pageLink(maxPage, pageNum, queries) }}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}

View File

@ -11,17 +11,17 @@
<main class="flex-container"> <main class="flex-container">
<form action="/maps" method="get" id="search"> <form action="/maps" method="get" id="search">
<h1>Search</h1> <h1>Search</h1>
<input type="text" name="map" id="map" placeholder="Map name"> <input type="text" name="map" id="map" placeholder="Map name" value="{{ options.query.map }}">
<input type="text" name="categories" id="categories" placeholder="Category"> <input type="text" name="categories" id="categories" placeholder="Category" value="{{ options.query.categories }}">
<input type="text" name="stars" id="stars" placeholder="Star amount"> <input type="text" name="stars" id="stars" placeholder="Star amount" value="{{ options.query.stars }}">
<div class="sorting"> <div class="sorting">
<label for="asc"> <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 Sort Ascending
</label> </label>
<label for="desc"> <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 Sort Descending
</label> </label>
</div> </div>
@ -30,7 +30,7 @@
</form> </form>
<div class="flex-container pages"> <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> </div>
{% for map in data.maps.maps %} {% for map in data.maps.maps %}