Skip to content

Commit 5042dd6

Browse files
committed
Remove preselected group logic from restaurant handlers
Simplifies the cookieReader function and related handler logic by removing support for preselecting a group via cookies. Updates the Index template to no longer require filterApplied or openGroup parameters.
1 parent 63b39fc commit 5042dd6

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

handlers/restaurants.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewMittagHandler(mittag *services.Mittag) *MittagHandler {
3030
}
3131
}
3232

33-
func cookieReader(ctx echo.Context, fav string) (map[string]string, string) {
33+
func cookieReader(ctx echo.Context, fav string) map[string]string {
3434
group := url.QueryEscape(ctx.QueryParam("group"))
3535

3636
favSet := make(map[string]string)
@@ -71,48 +71,27 @@ func cookieReader(ctx echo.Context, fav string) (map[string]string, string) {
7171
})
7272
}
7373

74-
if fav != "" && group != "" {
75-
ctx.SetCookie(&http.Cookie{
76-
Name: "lastGroup",
77-
Value: group,
78-
Path: "/",
79-
HttpOnly: true,
80-
MaxAge: 60,
81-
})
82-
}
83-
84-
var preselectedGroup string
85-
if lastFavCookie, err := ctx.Cookie("lastGroup"); err == nil {
86-
preselectedGroup, _ = url.QueryUnescape(lastFavCookie.Value)
87-
ctx.SetCookie(&http.Cookie{
88-
Name: "lastGroup",
89-
Value: "",
90-
Path: "/",
91-
MaxAge: -1,
92-
})
93-
}
94-
95-
return favSet, preselectedGroup
74+
return favSet
9675
}
9776

9877
func (m *MittagHandler) handleFilter(ctx echo.Context) error {
9978
q := ctx.QueryParam("q")
100-
favSet, _ := cookieReader(ctx, "")
79+
favSet := cookieReader(ctx, "")
10180
restaurants := config.GetGroupedRestaurants(favSet, q)
10281

103-
return render(ctx, views.Index(restaurants, q != "", ""))
82+
return render(ctx, views.Index(restaurants))
10483
}
10584

10685
func (m *MittagHandler) handleIndex(ctx echo.Context) error {
10786
fav := strings.ToLower(ctx.QueryParam("fav"))
108-
favSet, preselectedGroup := cookieReader(ctx, fav)
87+
favSet := cookieReader(ctx, fav)
10988

11089
if fav != "" {
11190
return ctx.Redirect(http.StatusFound, "/")
11291
}
11392

11493
restaurants := config.GetGroupedRestaurants(favSet, "")
115-
return render(ctx, views.HomeIndex(views.Index(restaurants, false, preselectedGroup)))
94+
return render(ctx, views.HomeIndex(views.Index(restaurants)))
11695
}
11796

11897
func (m *MittagHandler) handleUpload(ctx echo.Context) error {

views/index.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func spacing(isFavorite bool) string {
1313
return "my-2"
1414
}
1515

16-
templ Index(groups []config.GroupedRestaurants, filterApplied bool, openGroup string) {
16+
templ Index(groups []config.GroupedRestaurants) {
1717
if len(groups) > 0 {
1818
<div id="restaurants-container" class="grid gap-2">
1919
for _, g := range groups {

0 commit comments

Comments
 (0)