Fix nil Wishes crash
This commit is contained in:
parent
c7430bc942
commit
1caf06934f
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user