Add pages for search
This commit is contained in:
parent
043150d85b
commit
498e9282e9
|
@ -21,9 +21,9 @@ type SearchResult struct {
|
|||
RelTime string
|
||||
}
|
||||
|
||||
func (client *Client) Search(query string) ([]SearchResult, error) {
|
||||
func (client *Client) Search(query string, page string) ([]SearchResult, error) {
|
||||
query = url.QueryEscape(query)
|
||||
req, err := http.NewRequest("GET", "https://imgur.com/search?qs=list&q=" + query, nil)
|
||||
req, err := http.NewRequest("GET", "https://imgur.com/search/all/page/" + page + "?scrolled&q_size_is_mpx=off&qs=list&q=" + query, nil)
|
||||
if err != nil {
|
||||
return []SearchResult{}, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"codeberg.org/rimgo/rimgo/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
@ -17,7 +19,7 @@ func HandleSearch(c *fiber.Ctx) error {
|
|||
return c.Redirect(utils.ImgurRe.ReplaceAllString(query, ""))
|
||||
}
|
||||
|
||||
/*page := "1"
|
||||
page := "0"
|
||||
if c.Query("page") != "" {
|
||||
page = c.Query("page")
|
||||
}
|
||||
|
@ -28,11 +30,11 @@ func HandleSearch(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
displayPrevPage := true
|
||||
if page == "1" {
|
||||
if page == "0" {
|
||||
displayPrevPage = false
|
||||
}*/
|
||||
}
|
||||
|
||||
results, err := ApiClient.Search(query)
|
||||
results, err := ApiClient.Search(query, page)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -40,9 +42,9 @@ func HandleSearch(c *fiber.Ctx) error {
|
|||
return c.Render("search", fiber.Map{
|
||||
"query": query,
|
||||
"results": results,
|
||||
/*"page": page,
|
||||
"page": pageNumber + 1,
|
||||
"displayPrev": displayPrevPage,
|
||||
"nextPage": pageNumber + 1,
|
||||
"prevPage": pageNumber - 1,*/
|
||||
"prevPage": pageNumber - 1,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,6 +20,14 @@
|
|||
{{> partials/result }}
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between mt-4 font-bold">
|
||||
{{#if displayPrev}}
|
||||
<a href="/search?q={{query}}&page={{prevPage}}">Previous page</a>
|
||||
{{/if}}
|
||||
<p>Page {{page}}</p>
|
||||
<a href="/search?q={{query}}&page={{nextPage}}">Next page</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{{> partials/footer }}
|
||||
|
|
Loading…
Reference in New Issue