Cleanup previous/next page buttons (#134)
Use noteq to simplify code, add current page to previous/next page bar Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/134 Reviewed-by: orangix <orangix@noreply.codeberg.org> Co-authored-by: video-prize-ranch <cb.8a3w5@simplelogin.co> Co-committed-by: video-prize-ranch <cb.8a3w5@simplelogin.co>
This commit is contained in:
parent
0fea1e46a3
commit
fc88bfbca5
|
@ -29,11 +29,6 @@ func HandleSearch(c *fiber.Ctx) error {
|
|||
pageNumber = 0
|
||||
}
|
||||
|
||||
displayPrevPage := true
|
||||
if page == "0" {
|
||||
displayPrevPage = false
|
||||
}
|
||||
|
||||
results, err := ApiClient.Search(query, page)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -42,8 +37,7 @@ func HandleSearch(c *fiber.Ctx) error {
|
|||
return c.Render("search", fiber.Map{
|
||||
"query": query,
|
||||
"results": results,
|
||||
"page": pageNumber + 1,
|
||||
"displayPrev": displayPrevPage,
|
||||
"page": pageNumber,
|
||||
"nextPage": pageNumber + 1,
|
||||
"prevPage": pageNumber - 1,
|
||||
})
|
||||
|
|
|
@ -23,11 +23,6 @@ func HandleTag(c *fiber.Ctx) error {
|
|||
pageNumber = 0
|
||||
}
|
||||
|
||||
displayPrevPage := true
|
||||
if page == "1" {
|
||||
displayPrevPage = false
|
||||
}
|
||||
|
||||
tag, err := ApiClient.FetchTag(c.Params("tag"), c.Query("sort"), page)
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", fiber.Map{
|
||||
|
@ -44,7 +39,6 @@ func HandleTag(c *fiber.Ctx) error {
|
|||
return c.Render("tag", fiber.Map{
|
||||
"tag": tag,
|
||||
"page": page,
|
||||
"displayPrev": displayPrevPage,
|
||||
"nextPage": pageNumber + 1,
|
||||
"prevPage": pageNumber - 1,
|
||||
})
|
||||
|
|
|
@ -36,11 +36,6 @@ func HandleTrending(c *fiber.Ctx) error {
|
|||
sort = "popular"
|
||||
}
|
||||
|
||||
displayPrevPage := true
|
||||
if page == "1" {
|
||||
displayPrevPage = false
|
||||
}
|
||||
|
||||
results, err := ApiClient.FetchTrending(section, sort, page)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -51,7 +46,6 @@ func HandleTrending(c *fiber.Ctx) error {
|
|||
"section": section,
|
||||
"sort": sort,
|
||||
"page": pageNumber,
|
||||
"displayPrev": displayPrevPage,
|
||||
"nextPage": pageNumber + 1,
|
||||
"prevPage": pageNumber - 1,
|
||||
})
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
</div>
|
||||
|
||||
<div class="flex justify-between mt-4 font-bold">
|
||||
{{#if displayPrev}}
|
||||
{{#noteq page "0"}}
|
||||
<a href="/search?q={{query}}&page={{prevPage}}">Previous page</a>
|
||||
{{/if}}
|
||||
<p>Page {{page}}</p>
|
||||
{{/noteq}}
|
||||
<p>Page {{nextPage}}</p>
|
||||
<a href="/search?q={{query}}&page={{nextPage}}">Next page</a>
|
||||
</div>
|
||||
</main>
|
||||
|
|
|
@ -45,10 +45,11 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div class="mt-4 font-bold">
|
||||
{{#if displayPrev}}
|
||||
<div class="flex justify-between mt-4 font-bold">
|
||||
{{#noteq page "1"}}
|
||||
<a href="{{channel.RelUrl}}?page={{prevPage}}">Previous page</a>
|
||||
{{/if}}
|
||||
{{/noteq}}
|
||||
<p>Page {{nextPage}}</p>
|
||||
<a href="{{channel.RelUrl}}?page={{nextPage}}">Next page</a>
|
||||
</div>
|
||||
</main>
|
||||
|
|
|
@ -65,9 +65,9 @@
|
|||
</div>
|
||||
|
||||
<div class="flex justify-between mt-4 font-bold">
|
||||
{{#if displayPrev}}
|
||||
{{#noteq page "1"}}
|
||||
<a href="/trending?section={{section}}&sort={{sort}}&page={{prevPage}}">Previous page</a>
|
||||
{{/if}}
|
||||
{{/noteq}}
|
||||
<p>Page {{page}}</p>
|
||||
<a href="/trending?section={{section}}&sort={{sort}}&page={{nextPage}}">Next page</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue