internal/components/results.go (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 62 63 64 65 | package components import ( "go.alanpearce.eu/searchix/internal/config" g "go.alanpearce.eu/gomponents" . "go.alanpearce.eu/gomponents/html" ) func Results(r ResultData) g.Node { if r.Query == "" { return Br() } if r.Results == nil || r.Results.Total == 0 { return Span(Role("status"), g.Text("Nothing found")) } var content g.Node if r.Source != nil { switch r.Source.Importer { case config.Options: content = Options(r.Results) case config.Packages: content = Packages(r.Results) } } else { content = Combined(r.Results) } return g.Group([]g.Node{ content, Footer( g.Attr("aria-label", "pagination"), Nav( ID("pagination"), g.If(r.Prev != "", A(Class("button"), Href(r.Prev), Rel("prev"), g.Text("Prev")), ), g.If(r.Next != "", A(Class("button"), Href(r.Next), Rel("next"), g.Text("Next")), ), ), Span( Role("status"), g.Textf("%d results", r.Results.Total), ), g.If(r.Next != r.Prev && r.Results.Total < config.MaxResultsShowAll, A(Href(r.All), g.Text("Show All")), ), ), }) } func ResultsPage(r ResultData) g.Node { return SearchPage(r.TemplateData, r, Results(r)) } func openDialogLink(attr string) g.Node { return A(Class("open-dialog"), Href(attr), g.Text(attr)) } func openCombinedDialogLink(attr string) g.Node { return A(Class("open-dialog"), Href("/"+attr), g.Text(attr)) } |