diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index 95716d1..53d2ac5 100755 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -58,7 +58,18 @@ func HomePage(ctx *gin.Context) { return } - page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek) + if bytes, err := ctx.Cookie("search-filters"); err != nil { + fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error()) + page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, nil) + } else { + var filters domainRecipe.SearchFilters + if err := json.Unmarshal([]byte(bytes), &filters); err != nil { + fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error()) + page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, nil) + } else { + page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek, &filters) + } + } } else { // Get the recipe of the week recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil) @@ -70,7 +81,18 @@ func HomePage(ctx *gin.Context) { return } - page = templates.HomePage(false, nil, nil, recipeOfTheWeek) + if bytes, err := ctx.Cookie("search-filters"); err != nil { + fmt.Printf("ERROR: Failed to get search-filter cookie. %s\n", err.Error()) + page = templates.HomePage(false, nil, nil, recipeOfTheWeek, nil) + } else { + var filters domainRecipe.SearchFilters + if err := json.Unmarshal([]byte(bytes), &filters); err != nil { + fmt.Printf("ERROR: Failed to unmarshal search-filter cookie. %s\n", err.Error()) + page = templates.HomePage(false, nil, nil, recipeOfTheWeek, nil) + } else { + page = templates.HomePage(false, nil, nil, recipeOfTheWeek, &filters) + } + } } title := "Potion - Home" diff --git a/internal/templates/pages/home.templ b/internal/templates/pages/home.templ index 6d79d3c..d636b42 100644 --- a/internal/templates/pages/home.templ +++ b/internal/templates/pages/home.templ @@ -5,132 +5,126 @@ import "github.com/haydenhargreaves/Potion/internal/domain/server" import domainRecipe "github.com/haydenhargreaves/Potion/internal/domain/recipe" templ introSection() { -
-
- -

- Discover Your Next Favorite Meal -

-
-

- Welcome to your ultimate recipe hub! Whether you're a seasoned chef or just starting your culinary adventure, - we're here to inspire. Explore thousands of delicious recipes, from quick weeknight dinners to gourmet delights, - all at your fingertips. Find exactly what you're craving with our powerful search and intuitive filters, or - browse our trending dishes for fresh ideas. -

-
+
+
+ +

+ Discover Your Next Favorite Meal +

+
+

+ Welcome to your ultimate recipe hub! Whether you're a seasoned chef or just starting your culinary adventure, + we're here to inspire. Explore thousands of delicious recipes, from quick weeknight dinners to gourmet delights, + all at your fingertips. Find exactly what you're craving with our powerful search and intuitive filters, or + browse our trending dishes for fresh ideas. +

+
} -templ searchSection() { -
- @components.BannerText("Craving Something Specific?") -
- @components.SearchBar(nil, true, false, false) -
- -
+templ searchSection(filters *domainRecipe.SearchFilters) { +
+ @components.BannerText("Craving Something Specific?") +
+ @components.SearchBar(filters, true, false, false) +
+ +
} templ highlightSection(recipeOfTheWeek *domainRecipe.Recipe) { -
- @components.BannerText("Recipe of the Week!") -

- Our 'Recipe of the Week' is the cream of the crop! We handpick it by looking at what recipes - our community loves most. This isn't just about how many people view a recipe; it's also about - how many times it's been made, liked, reviewed, and its average rating, all combined to find - the true fan favorite of the week. It's our way of highlighting the best recipes that truly - resonate with our users! -

-
- @components.RecipeCardLarge(recipeOfTheWeek) -
-
+
+ @components.BannerText("Recipe of the Week!") +

+ Our 'Recipe of the Week' is the cream of the crop! We handpick it by looking at what recipes + our community loves most. This isn't just about how many people view a recipe; it's also about + how many times it's been made, liked, reviewed, and its average rating, all combined to find + the true fan favorite of the week. It's our way of highlighting the best recipes that truly + resonate with our users! +

+
+ @components.RecipeCardLarge(recipeOfTheWeek) +
+
} templ listsSection(loggedIn bool, viewed, made []domainRecipe.Recipe) { -
- @components.BannerText("Take Another Look.") -
-

Recently viewed

- if loggedIn { -
- if len(viewed) > 0 { - for _, recipe := range viewed { - @components.RecipeCardSmall(recipe) - } - @components.ContentCardSmall("View full history...", "/v1/web/history") - } else { -

You have not viewed any recipes. There is nothing to show.

- } -
- } else { - - } -

Make again

- if loggedIn { -
- if len(made) > 0 { - for _, recipe := range made { - @components.RecipeCardSmall(recipe) - } - @components.ContentCardSmall("View full history...", "/v1/web/history") - } else { -

You have not made any recipes. There is nothing to show.

- } -
- } else { - - } -
-
+
+ @components.BannerText("Take Another Look.") +
+

Recently viewed

+ if loggedIn { +
+ if len(viewed) > 0 { + for _, recipe := range viewed { + @components.RecipeCardSmall(recipe) + } + @components.ContentCardSmall("View full history...", "/v1/web/history") + } else { +

You have not viewed any recipes. There is nothing to show.

+ } +
+ } else { + + } +

Make again

+ if loggedIn { +
+ if len(made) > 0 { + for _, recipe := range made { + @components.RecipeCardSmall(recipe) + } + @components.ContentCardSmall("View full history...", "/v1/web/history") + } else { +

You have not made any recipes. There is nothing to show.

+ } +
+ } else { + + } +
+
} templ ctaSection() { -
-

- Unleash Your Inner Chef! -

-

- Have a unique recipe idea? Want to share your culinary masterpiece with the world? - It's time to bring your creations to life! -

- +

+ Unleash Your Inner Chef! +

+

+ Have a unique recipe idea? Want to share your culinary masterpiece with the world? + It's time to bring your creations to life! +

+
- Create Your Recipe! - -
+ text-lg md:text-2xl font-bold uppercase tracking-wide"> + Create Your Recipe! + + } -templ HomePage(loggedIn bool, viewed, made []domainRecipe.Recipe, recipeOfTheWeek *domainRecipe.Recipe) { - @components.Navbar("home") -
-
- @introSection() - @searchSection() - @highlightSection(recipeOfTheWeek) - @listsSection(loggedIn, viewed, made) - @ctaSection() -
-
+templ HomePage(loggedIn bool, viewed, made []domainRecipe.Recipe, recipeOfTheWeek *domainRecipe.Recipe, filters *domainRecipe.SearchFilters) { +@components.Navbar("home") +
+
+ @introSection() + @searchSection(filters) + @highlightSection(recipeOfTheWeek) + @listsSection(loggedIn, viewed, made) + @ctaSection() +
+
} diff --git a/internal/templates/pages/home_templ.go b/internal/templates/pages/home_templ.go index 5b5f014..179c7aa 100644 --- a/internal/templates/pages/home_templ.go +++ b/internal/templates/pages/home_templ.go @@ -41,7 +41,7 @@ func introSection() templ.Component { }) } -func searchSection() templ.Component { +func searchSection(filters *domainRecipe.SearchFilters) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -74,7 +74,7 @@ func searchSection() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = components.SearchBar(nil, true, false, false).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = components.SearchBar(filters, true, false, false).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -304,7 +304,7 @@ func ctaSection() templ.Component { }) } -func HomePage(loggedIn bool, viewed, made []domainRecipe.Recipe, recipeOfTheWeek *domainRecipe.Recipe) templ.Component { +func HomePage(loggedIn bool, viewed, made []domainRecipe.Recipe, recipeOfTheWeek *domainRecipe.Recipe, filters *domainRecipe.SearchFilters) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -337,7 +337,7 @@ func HomePage(loggedIn bool, viewed, made []domainRecipe.Recipe, recipeOfTheWeek if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = searchSection().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = searchSection(filters).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }