diff --git a/http/resources/home.go b/http/resources/home.go index ea3f1b8..7809eea 100644 --- a/http/resources/home.go +++ b/http/resources/home.go @@ -181,6 +181,10 @@ func (w Wishlist) ExtractFormValues(form url.Values) { w.NewWish.Elements.ExtractFormValue(form) } + if w.Wishes == nil { + return + } + err := w.Wishes.Elements.Select.ExtractFormValue(form) if err != nil { w.Wishes.Elements.Select.Error = err.Error() diff --git a/http/routing/home.go b/http/routing/home.go index 354eaeb..57a4f99 100644 --- a/http/routing/home.go +++ b/http/routing/home.go @@ -90,7 +90,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter p.Warning = "Extraneous form values" } - if p.Wishlist.Wishes.Elements.Intent.Value() == "delete" { + if p.Wishlist.Wishes != nil && p.Wishlist.Wishes.Elements.Intent.Value() == "delete" { wishesToDelete := slices.Collect(p.Wishlist.Wishes.Elements.Select.Values()) err := app.RevokeWishes(wishesToDelete...) if err != nil { @@ -109,16 +109,16 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter } } - todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values()) - - if p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" { + if p.Todo.Wishes != nil && p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" { + todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values()) err := app.ClaimWishes([]string{}, todosToChange) if err != nil { log.Printf("Failed to unclaim wish: %s\n", err) p.Todo.Wishes.Elements.Intent.Error = "Something went wrong" return rsvp.Data(p).StatusInternalServerError() } - } else if p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" { + } else if p.Todo.Wishes != nil && p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" { + todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values()) err := app.CompleteWishes(todosToChange) if err != nil { log.Printf("Failed to complete wish: %s\n", err)