about summary refs log tree commit diff stats
path: root/internal/components/packages.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/components/packages.go')
-rw-r--r--internal/components/packages.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/components/packages.go b/internal/components/packages.go
new file mode 100644
index 0000000..9bc3f99
--- /dev/null
+++ b/internal/components/packages.go
@@ -0,0 +1,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),
+			),
+		),
+	)
+}