Fix nil Wishes crash

This commit is contained in:
Teajey 2026-11-18 00:11:55 +09:00
parent c7430bc942
commit 1caf06934f
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View File

@ -181,6 +181,10 @@ func (w Wishlist) ExtractFormValues(form url.Values) {
w.NewWish.Elements.ExtractFormValue(form) w.NewWish.Elements.ExtractFormValue(form)
} }
if w.Wishes == nil {
return
}
err := w.Wishes.Elements.Select.ExtractFormValue(form) err := w.Wishes.Elements.Select.ExtractFormValue(form)
if err != nil { if err != nil {
w.Wishes.Elements.Select.Error = err.Error() w.Wishes.Elements.Select.Error = err.Error()

View File

@ -90,7 +90,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
p.Warning = "Extraneous form values" 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()) wishesToDelete := slices.Collect(p.Wishlist.Wishes.Elements.Select.Values())
err := app.RevokeWishes(wishesToDelete...) err := app.RevokeWishes(wishesToDelete...)
if err != nil { 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 != nil && p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
if p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
err := app.ClaimWishes([]string{}, todosToChange) err := app.ClaimWishes([]string{}, todosToChange)
if err != nil { if err != nil {
log.Printf("Failed to unclaim wish: %s\n", err) log.Printf("Failed to unclaim wish: %s\n", err)
p.Todo.Wishes.Elements.Intent.Error = "Something went wrong" p.Todo.Wishes.Elements.Intent.Error = "Something went wrong"
return rsvp.Data(p).StatusInternalServerError() 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) err := app.CompleteWishes(todosToChange)
if err != nil { if err != nil {
log.Printf("Failed to complete wish: %s\n", err) log.Printf("Failed to complete wish: %s\n", err)