about summary refs log tree commit diff stats
path: root/internal/components/results.templ
blob: b051219130bb5179202ef1f3e57c7a39dc1ee15b (plain)
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
package components

import (
	"strconv"
	"go.alanpearce.eu/searchix/internal/nix"
)

func convertMatch[I nix.Importable](m nix.Importable) *I {
	i := m.(I)
	return &i
}

templ Results(r ResultData) {
	if r.Query != "" {
		if r.Results != nil && r.Results.Total > 0 {
			switch r.Results.Hits[0].Data.(type) {
				case nix.Option:
					@Options(r.Results)
				case nix.Package:
					@Packages(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>
}