about summary refs log tree commit diff stats
path: root/internal/components/options.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/components/options.go')
-rw-r--r--internal/components/options.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/components/options.go b/internal/components/options.go
new file mode 100644
index 0000000..af6c73f
--- /dev/null
+++ b/internal/components/options.go
@@ -0,0 +1,50 @@
+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 Options(result *index.Result) g.Node {
+	return Table(
+		THead(
+			Tr(
+				Th(Scope("col"), g.Text("Title")),
+				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.Option](hit.Data); m != nil {
+					return optionRow(hit, *m)
+				}
+
+				return nil
+			}),
+		),
+	)
+}
+
+func optionRow(hit index.DocumentMatch, o nix.Option) g.Node {
+	return Tr(
+		Td(
+			openDialogLink(o.Name),
+		),
+		Td(
+			firstSentence(o.Description),
+			Dialog(ID(o.Name)),
+		),
+		g.If(config.DevMode,
+			Td(
+				Score(hit),
+			),
+		),
+	)
+}