From c0fc47c569b3917cfd25736d985e077f421b2436 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Mon, 7 Jul 2025 21:36:13 -0700 Subject: [PATCH] (UI): UI implementation of the search page. Somewhat wired up. Missing some context storage and better passing of data to allow between the home page to the search page. Need a way to store the search results in state so they can be retrieved when the page is reloaded, etc. --- internal/app/handlers/page_handler.go | 23 +- internal/app/handlers/recipe_handler.go | 12 +- internal/app/server/server.go | 1 + .../database/repository/recipe_repository.go | 2 + internal/templates/components/dropdowns.templ | 124 +++--- .../templates/components/dropdowns_templ.go | 12 +- .../templates/components/search_bar.templ | 74 ++++ .../templates/components/search_bar_templ.go | 100 +++++ internal/templates/pages/home.templ | 73 +--- internal/templates/pages/home_templ.go | 145 ++----- internal/templates/pages/search.templ | 129 +++++++ internal/templates/pages/search_templ.go | 361 ++++++++++++++++++ internal/templates/partials/row.templ | 0 internal/templates/partials/row_templ.go | 10 - web/static/css/tailwind.css | 116 +++--- 15 files changed, 855 insertions(+), 327 deletions(-) create mode 100644 internal/templates/components/search_bar.templ create mode 100644 internal/templates/components/search_bar_templ.go create mode 100644 internal/templates/pages/search.templ create mode 100644 internal/templates/pages/search_templ.go delete mode 100644 internal/templates/partials/row.templ delete mode 100644 internal/templates/partials/row_templ.go diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index 1f87c36..82d3d62 100644 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -15,21 +15,21 @@ func LoginPage(ctx *gin.Context) { title := "Potion - Login" page := pages.LoginPage() - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } func HomePage(ctx *gin.Context) { title := "Potion - Home" page := pages.HomePage() - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } func FavoritesPage(ctx *gin.Context) { title := "Potion - Favorites" page := pages.FavoritesPage() - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } func CreatePage(ctx *gin.Context) { @@ -42,7 +42,7 @@ func CreatePage(ctx *gin.Context) { title := "Potion - Create" page := pages.CreatePage() - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } func ProfilePage(ctx *gin.Context) { @@ -59,14 +59,14 @@ func ProfilePage(ctx *gin.Context) { title := "Potion - Profile" page := pages.ProfilePage(user) - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } func ListPage(ctx *gin.Context) { title := "Potion - Shopping List" page := pages.ListPage() - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } // TODO: Figure out how to handle errors, think we just need a simple display. @@ -102,5 +102,14 @@ func RecipePage(ctx *gin.Context) { title := "Potion - View Recipe" page := pages.RecipePage(*recipe, *user) - ctx.HTML(200, "", layouts.AppLayout(title, page)) + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) +} + +func SearchPage(ctx *gin.Context) { + title := "Potion - Recipe Search" + page := pages.SearchPage() + + fmt.Println("I OPENED A PAGE!") + + ctx.HTML(http.StatusOK, "", layouts.AppLayout(title, page)) } diff --git a/internal/app/handlers/recipe_handler.go b/internal/app/handlers/recipe_handler.go index 7854a98..2490927 100644 --- a/internal/app/handlers/recipe_handler.go +++ b/internal/app/handlers/recipe_handler.go @@ -6,14 +6,9 @@ import ( "github.com/gin-gonic/gin" domain "github.com/haydenhargreaves/Potion/internal/domain/server" + templates "github.com/haydenhargreaves/Potion/internal/templates/pages" ) -const CREATE_SUCCESS_HTML = ` -

- Success! Your new masterpiece was created! -

-` - const CREATE_ERROR_HTML = `

Uh oh! Something went wrong when creating your recipe. Please try again. %s @@ -42,5 +37,8 @@ func SearchRecipes(ctx *gin.Context) { if err != nil { ctx.JSON(http.StatusOK, gin.H{"error": err.Error()}) } - ctx.JSON(http.StatusOK, gin.H{"recipes": recipes}) + + // Render content as the response + ctx.Status(200) + templates.ResultList(recipes).Render(ctx.Request.Context(), ctx.Writer) } diff --git a/internal/app/server/server.go b/internal/app/server/server.go index b972deb..5ec329f 100644 --- a/internal/app/server/server.go +++ b/internal/app/server/server.go @@ -165,6 +165,7 @@ func (s *Server) Setup() *Server { router_web.GET("/profile", handlers.ProfilePage) router_web.GET("/list", handlers.ListPage) router_web.GET("/recipe/:id", handlers.RecipePage) + router_web.GET("/search", handlers.SearchPage) // WEB state endpoints router_state.POST("/tags", handlers.NewTag) diff --git a/internal/infrastructure/database/repository/recipe_repository.go b/internal/infrastructure/database/repository/recipe_repository.go index 6727448..973e6c2 100644 --- a/internal/infrastructure/database/repository/recipe_repository.go +++ b/internal/infrastructure/database/repository/recipe_repository.go @@ -259,6 +259,8 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters) ([]domain query += ";" } + fmt.Println(query) + // Execute the query rows, err := tx.Query(query) if err != nil { diff --git a/internal/templates/components/dropdowns.templ b/internal/templates/components/dropdowns.templ index 226efc8..43f858d 100644 --- a/internal/templates/components/dropdowns.templ +++ b/internal/templates/components/dropdowns.templ @@ -1,19 +1,17 @@ package components templ dropdownButton(content, name, value string) { - + } templ FilterDropdown() { - -

-} + + } diff --git a/internal/templates/components/dropdowns_templ.go b/internal/templates/components/dropdowns_templ.go index e6605c4..4a1373d 100644 --- a/internal/templates/components/dropdowns_templ.go +++ b/internal/templates/components/dropdowns_templ.go @@ -29,7 +29,7 @@ func dropdownButton(content, name, value string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "