about summary refs log tree commit diff stats
path: root/internal/components/packages.go
blob: 9bc3f994c8b63c038d888b4935a795100ba2eaf9 (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
50
51
52
53
package components

import (
	"go.alanpearce.eu/searchix/internal/config"
	"go.alanpearce.eu/searchix/internal/index"
	"go.alanpearce.eu/searchix/internal/nix"

	g "go.alanpearce.eu/gomponents"
	. "go.alanpearce.eu/gomponents/html"
)

func Packages(result *index.Result) g.Node {
	return Table(
		THead(
			Tr(
				Th(Scope("col"), g.Text("Attribute")),
				Th(Scope("col"), g.Text("Name")),
				Th(Scope("col"), g.Text("Description")),
				g.If(config.DevMode,
					Th(Scope("col"), g.Text("Score")),
				),
			),
		),
		TBody(
			g.Map(result.Hits, func(hit index.DocumentMatch) g.Node {
				if m := convertMatch[nix.Package](hit.Data); m != nil {
					return packageRow(hit, *m)
				}

				return nil
			}),
		),
	)
}

func packageRow(hit index.DocumentMatch, p nix.Package) g.Node {
	return Tr(
		Td(
			openDialogLink(p.Attribute),
		),
		Td(
			g.Text(p.Name),
		),
		Td(
			g.Text(p.Description),
		),
		g.If(config.DevMode,
			Td(
				Score(hit),
			),
		),
	)
}