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:
video-prize-ranch 2023-08-30 17:24:54 +00:00 committed by video-prize-ranch
parent 0fea1e46a3
commit fc88bfbca5
6 changed files with 10 additions and 27 deletions

View File

@ -29,11 +29,6 @@ func HandleSearch(c *fiber.Ctx) error {
pageNumber = 0 pageNumber = 0
} }
displayPrevPage := true
if page == "0" {
displayPrevPage = false
}
results, err := ApiClient.Search(query, page) results, err := ApiClient.Search(query, page)
if err != nil { if err != nil {
return err return err
@ -42,8 +37,7 @@ func HandleSearch(c *fiber.Ctx) error {
return c.Render("search", fiber.Map{ return c.Render("search", fiber.Map{
"query": query, "query": query,
"results": results, "results": results,
"page": pageNumber + 1, "page": pageNumber,
"displayPrev": displayPrevPage,
"nextPage": pageNumber + 1, "nextPage": pageNumber + 1,
"prevPage": pageNumber - 1, "prevPage": pageNumber - 1,
}) })

View File

@ -23,11 +23,6 @@ func HandleTag(c *fiber.Ctx) error {
pageNumber = 0 pageNumber = 0
} }
displayPrevPage := true
if page == "1" {
displayPrevPage = false
}
tag, err := ApiClient.FetchTag(c.Params("tag"), c.Query("sort"), page) tag, err := ApiClient.FetchTag(c.Params("tag"), c.Query("sort"), page)
if err != nil && err.Error() == "ratelimited by imgur" { if err != nil && err.Error() == "ratelimited by imgur" {
return c.Status(429).Render("errors/429", fiber.Map{ 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{ return c.Render("tag", fiber.Map{
"tag": tag, "tag": tag,
"page": page, "page": page,
"displayPrev": displayPrevPage,
"nextPage": pageNumber + 1, "nextPage": pageNumber + 1,
"prevPage": pageNumber - 1, "prevPage": pageNumber - 1,
}) })

View File

@ -36,11 +36,6 @@ func HandleTrending(c *fiber.Ctx) error {
sort = "popular" sort = "popular"
} }
displayPrevPage := true
if page == "1" {
displayPrevPage = false
}
results, err := ApiClient.FetchTrending(section, sort, page) results, err := ApiClient.FetchTrending(section, sort, page)
if err != nil { if err != nil {
return err return err
@ -51,7 +46,6 @@ func HandleTrending(c *fiber.Ctx) error {
"section": section, "section": section,
"sort": sort, "sort": sort,
"page": pageNumber, "page": pageNumber,
"displayPrev": displayPrevPage,
"nextPage": pageNumber + 1, "nextPage": pageNumber + 1,
"prevPage": pageNumber - 1, "prevPage": pageNumber - 1,
}) })

View File

@ -22,10 +22,10 @@
</div> </div>
<div class="flex justify-between mt-4 font-bold"> <div class="flex justify-between mt-4 font-bold">
{{#if displayPrev}} {{#noteq page "0"}}
<a href="/search?q={{query}}&page={{prevPage}}">Previous page</a> <a href="/search?q={{query}}&page={{prevPage}}">Previous page</a>
{{/if}} {{/noteq}}
<p>Page {{page}}</p> <p>Page {{nextPage}}</p>
<a href="/search?q={{query}}&page={{nextPage}}">Next page</a> <a href="/search?q={{query}}&page={{nextPage}}">Next page</a>
</div> </div>
</main> </main>

View File

@ -45,10 +45,11 @@
{{/each}} {{/each}}
</div> </div>
<div class="mt-4 font-bold"> <div class="flex justify-between mt-4 font-bold">
{{#if displayPrev}} {{#noteq page "1"}}
<a href="{{channel.RelUrl}}?page={{prevPage}}">Previous page</a> <a href="{{channel.RelUrl}}?page={{prevPage}}">Previous page</a>
{{/if}} {{/noteq}}
<p>Page {{nextPage}}</p>
<a href="{{channel.RelUrl}}?page={{nextPage}}">Next page</a> <a href="{{channel.RelUrl}}?page={{nextPage}}">Next page</a>
</div> </div>
</main> </main>

View File

@ -65,9 +65,9 @@
</div> </div>
<div class="flex justify-between mt-4 font-bold"> <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> <a href="/trending?section={{section}}&sort={{sort}}&page={{prevPage}}">Previous page</a>
{{/if}} {{/noteq}}
<p>Page {{page}}</p> <p>Page {{page}}</p>
<a href="/trending?section={{section}}&sort={{sort}}&page={{nextPage}}">Next page</a> <a href="/trending?section={{section}}&sort={{sort}}&page={{nextPage}}">Next page</a>
</div> </div>