Fix bug related to arguments not being transferred over pages

This commit is contained in:
magmaus3 2022-10-31 17:35:33 +01:00
parent fd2480ec45
commit 2dcf6d7c9e
Signed by: magmaus3
GPG key ID: 966755D3F4A9B251
2 changed files with 10 additions and 8 deletions

View file

@ -38,7 +38,7 @@ async def root():
async def search(
q: Union[str, None] = None,
p: int = 0,
sort: str = "average_Rating",
sort: str = "average_rating",
dir: str = "desc",
date: int = -1
):
@ -46,7 +46,9 @@ async def search(
limit = 10
if p is None:
p = 0
# Passed to the template
QueryValues = {"q": q, "p": p, "sort": sort, "dir": dir, "date": date}
searchResults = None
if q is not None:
@ -115,12 +117,11 @@ async def search(
entryNumber = None
return template.render(
searchValue=searchValue,
searchPage=p,
searchResults=searchResults,
THUMB_URL=THUMB_URL,
entryLimit=limit,
entryNumber=entryNumber
entryNumber=entryNumber,
QueryValues=QueryValues
)
@app.get("/level/{level_id}", response_class=HTMLResponse)

View file

@ -27,7 +27,7 @@
<div class='searchBar'>
<form action="/search" method="get">
<div class="search_entry">
<input type='text' id="q" name="q" value='{{ searchValue }}' placeholder="Enter a level name or code"/>
<input type='text' id="q" name="q" value='{{ QueryValues["q"] }}' placeholder="Enter a level name or code"/>
<button class="searchButton" id='searchButton' type='submit'>🔍</button>
</div>
<details>
@ -83,9 +83,10 @@
</div>
<div class="searchResultsFooter">
{% set searchPage = QueryValues['p'] %}
<p>Page {{ searchPage+1 }}</p>
{% if not searchPage <= 0 %}<a href="/search?q={{ searchValue }}&p={{ searchPage-1 }}">Prev</a>{% endif %}
{% if not entryNumber < entryLimit %}<a href="/search?q={{ searchValue }}&p={{ searchPage+1 }}">Next</a>{% endif %}
{% if not searchPage <= 0 %}<a href="/search?q={{ QueryValues['q'] }}&sort={{ QueryValues['sort'] }}&dir={{ QueryValues['dir'] }}&date={{ QueryValues['date'] }}&p={{ QueryValues['p']-1 }}">Prev</a>{% endif %}
{% if not entryNumber < entryLimit %}<a href="/search?q={{ QueryValues['q'] }}&sort={{ QueryValues['sort'] }}&dir={{ QueryValues['dir'] }}&date={{ QueryValues['date'] }}&p={{ QueryValues['p']+1 }}">Next</a>{% endif %}
</div>
</div>
{% endif %}