internal/components/results.templ (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | package components
import (
"strconv"
"go.alanpearce.eu/searchix/internal/nix"
"go.alanpearce.eu/searchix/internal/config"
)
func convertMatch[I nix.Importable](m nix.Importable) *I {
i, ok := m.(I)
if !ok {
return nil
}
return &i
}
templ Results(r ResultData) {
if r.Query != "" {
if r.Results != nil && r.Results.Total > 0 {
if r.Source != nil {
switch r.Source.Importer {
case config.Options:
@Options(r.Results)
case config.Packages:
@Packages(r.Results)
}
} else {
@Combined(r.Results)
}
<footer aria-label="pagination">
<nav id="pagination">
if r.Prev != "" {
<a class="button" href={ templ.SafeURL(r.Prev) } rel="prev">Prev</a>
}
if r.Next != "" {
<a class="button" href={ templ.SafeURL(r.Next) } rel="next">Next</a>
}
</nav>
<span role="status">{ strconv.FormatUint(r.Results.Total, 10) } results</span>
</footer>
} else {
<span role="status">Nothing found</span>
}
} else {
<br/>
}
}
templ ResultsPage(r ResultData) {
@SearchPage(r.TemplateData, r) {
@Results(r)
}
}
templ openDialogLink(attr string) {
<a class="open-dialog" href={ templ.SafeURL(attr) }>{ attr }</a>
}
templ openCombinedDialogLink(attr string) {
<a class="open-dialog" href={ templ.SafeURL("/" + attr) }>{ attr }</a>
}
|