41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
"mal/integrations/jikan"
|
|
ui "mal/web/components"
|
|
"mal/web/shared/layout"
|
|
"net/url"
|
|
)
|
|
|
|
templ Search(q string) {
|
|
@layout.Layout("mal - search", true) {
|
|
if q != "" {
|
|
<div id="loading" class="hidden htmx-request:inline-flex">
|
|
@ui.LoadingIndicator("Searching...")
|
|
</div>
|
|
<div id="results" hx-get={ string(templ.URL("/search?q=" + url.QueryEscape(q))) } hx-trigger="load" hx-indicator="#loading"></div>
|
|
} else {
|
|
@ui.EmptyState("Search for anime") {
|
|
Use the search bar above to find anime to add to your watchlist.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
templ SearchResultsWrapper(query string, animes []jikan.Anime, nextPage int, hasNext bool) {
|
|
if len(animes) == 0 {
|
|
@ui.EmptyState("No results found.") {
|
|
Try a different search term.
|
|
}
|
|
} else {
|
|
<div class="grid grid-cols-2 gap-3 sm:grid-cols-3 md:gap-4 lg:grid-cols-4 xl:grid-cols-5">
|
|
@SearchItems(query, animes, nextPage, hasNext)
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ SearchItems(query string, animes []jikan.Anime, nextPage int, hasNext bool) {
|
|
@ui.InfiniteAnimeList(animes, hasNext, string(templ.URL(fmt.Sprintf("/api/search?q=%s&page=%d", url.QueryEscape(query), nextPage))), "results")
|
|
}
|