40 lines
1.0 KiB
Plaintext
40 lines
1.0 KiB
Plaintext
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
"mal/internal/jikan"
|
|
"mal/internal/shared/ui"
|
|
"net/url"
|
|
)
|
|
|
|
templ Search(q string) {
|
|
@Layout("mal - search") {
|
|
if q != "" {
|
|
<div id="loading" class="htmx-indicator">
|
|
@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="catalog-grid">
|
|
@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")
|
|
}
|