diff --git a/pkg/handlers/search.go b/pkg/handlers/search.go
index 1406faf..687bd50 100644
--- a/pkg/handlers/search.go
+++ b/pkg/handlers/search.go
@@ -4,10 +4,13 @@ import (
"fmt"
"math/rand"
+ "github.com/a-h/templ"
"github.com/labstack/echo/v4"
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
"git.grosinger.net/tgrosinger/saasitone/pkg/services"
+ "git.grosinger.net/tgrosinger/saasitone/templ/layouts"
+ "git.grosinger.net/tgrosinger/saasitone/templ/pages"
"git.grosinger.net/tgrosinger/saasitone/templates"
)
@@ -17,11 +20,6 @@ type (
Search struct {
*services.TemplateRenderer
}
-
- searchResult struct {
- Title string
- URL string
- }
)
func init() {
@@ -39,23 +37,28 @@ func (h *Search) Routes(g *echo.Group) {
func (h *Search) Page(ctx echo.Context) error {
p := page.New(ctx)
- p.Layout = templates.LayoutMain
p.Name = templates.PageSearch
// Fake search results
- var results []searchResult
+ var results []pages.SearchResult
if search := ctx.QueryParam("query"); search != "" {
for i := 0; i < 5; i++ {
title := "Lorem ipsum example ddolor sit amet"
index := rand.Intn(len(title))
title = title[:index] + search + title[index:]
- results = append(results, searchResult{
+ results = append(results, pages.SearchResult{
Title: title,
URL: fmt.Sprintf("https://www.%s.com", search),
})
}
}
- p.Data = results
- return h.RenderPage(ctx, p)
+ component := pages.Search(p, results)
+
+ // TODO: This can be reused
+ p.LayoutComponent = func(content templ.Component) templ.Component {
+ return layouts.Main(p, content)
+ }
+
+ return h.RenderPageTempl(ctx, p, component)
}
diff --git a/templ/pages/search.templ b/templ/pages/search.templ
new file mode 100644
index 0000000..8cbf156
--- /dev/null
+++ b/templ/pages/search.templ
@@ -0,0 +1,14 @@
+package pages
+
+import "git.grosinger.net/tgrosinger/saasitone/pkg/page"
+
+type SearchResult struct {
+ Title string
+ URL string
+}
+
+templ Search(p page.Page, results []SearchResult) {
+ for _, result := range results {
+ { result.Title }
+ }
+}
diff --git a/templ/pages/search_templ.go b/templ/pages/search_templ.go
new file mode 100644
index 0000000..f4b3cbb
--- /dev/null
+++ b/templ/pages/search_templ.go
@@ -0,0 +1,66 @@
+// Code generated by templ - DO NOT EDIT.
+
+// templ: version: v0.2.707
+package pages
+
+//lint:file-ignore SA4006 This context is only used if a nested component is present.
+
+import "github.com/a-h/templ"
+import "context"
+import "io"
+import "bytes"
+
+import "git.grosinger.net/tgrosinger/saasitone/pkg/page"
+
+type SearchResult struct {
+ Title string
+ URL string
+}
+
+func Search(p page.Page, results []SearchResult) templ.Component {
+ return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
+ if !templ_7745c5c3_IsBuffer {
+ templ_7745c5c3_Buffer = templ.GetBuffer()
+ defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var1 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var1 == nil {
+ templ_7745c5c3_Var1 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ for _, result := range results {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var3 string
+ templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(result.Title)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/pages/search.templ`, Line: 12, Col: 70}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ if !templ_7745c5c3_IsBuffer {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
+ }
+ return templ_7745c5c3_Err
+ })
+}
diff --git a/templates/pages/search.gohtml b/templates/pages/search.gohtml
deleted file mode 100644
index dc32fb6..0000000
--- a/templates/pages/search.gohtml
+++ /dev/null
@@ -1,5 +0,0 @@
-{{define "content"}}
- {{- range .Data}}
- {{.Title}}
- {{- end}}
-{{end}}
\ No newline at end of file