Compare commits
No commits in common. "1caf06934fdc60ce35be4d9876ead98457dbdc0e" and "b5dfb135df50a68193cc8dc6b0ede1fb9f4f092e" have entirely different histories.
1caf06934f
...
b5dfb135df
@ -37,26 +37,11 @@ type Wishes struct {
|
||||
|
||||
type Wishlist struct {
|
||||
Label string `json:"label" xml:",chardata"`
|
||||
Wishes *hmc.Form[Wishes] `json:"wishes"`
|
||||
Wishes hmc.Form[Wishes] `json:"wishes"`
|
||||
NewWish *hmc.Form[hmc.Input] `json:"new_wish"`
|
||||
}
|
||||
|
||||
func InitialWishlist(wishes []lishwist.Wish) Wishlist {
|
||||
list := Wishlist{
|
||||
Label: "Your wishlist",
|
||||
NewWish: &hmc.Form[hmc.Input]{
|
||||
Method: "POST",
|
||||
Elements: hmc.Input{
|
||||
Label: "Add gift idea",
|
||||
Name: "gift_name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if len(wishes) < 1 {
|
||||
return list
|
||||
}
|
||||
|
||||
func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
|
||||
wishInputs := make([]hmc.Option, len(wishes))
|
||||
items := make([]Wish, len(wishes))
|
||||
|
||||
@ -77,41 +62,41 @@ func InitialWishlist(wishes []lishwist.Wish) Wishlist {
|
||||
}
|
||||
}
|
||||
|
||||
list.Wishes = &hmc.Form[Wishes]{
|
||||
Method: "POST",
|
||||
Elements: Wishes{
|
||||
Items: items,
|
||||
Select: hmc.Select{
|
||||
Label: "Wishes",
|
||||
Multiple: true,
|
||||
Name: "wish",
|
||||
Required: true,
|
||||
Options: wishInputs,
|
||||
return Wishlist{
|
||||
Label: "Your wishlist",
|
||||
Wishes: hmc.Form[Wishes]{
|
||||
Method: "POST",
|
||||
Elements: Wishes{
|
||||
Items: items,
|
||||
Select: hmc.Select{
|
||||
Label: "Wishes",
|
||||
Multiple: true,
|
||||
Name: "wish",
|
||||
Required: true,
|
||||
Options: wishInputs,
|
||||
},
|
||||
Intent: hmc.Select{
|
||||
Label: "Intent",
|
||||
Required: true,
|
||||
Name: "intent",
|
||||
Options: []hmc.Option{{
|
||||
Label: "Delete",
|
||||
Value: "delete",
|
||||
}},
|
||||
},
|
||||
},
|
||||
Intent: hmc.Select{
|
||||
Label: "Intent",
|
||||
Required: true,
|
||||
Name: "intent",
|
||||
Options: []hmc.Option{{
|
||||
Label: "Delete",
|
||||
Value: "delete",
|
||||
}},
|
||||
},
|
||||
NewWish: &hmc.Form[hmc.Input]{
|
||||
Method: "POST",
|
||||
Elements: hmc.Input{
|
||||
Label: "Add gift idea",
|
||||
Name: "gift_name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
func InitialTodo(todo []lishwist.Wish) Wishlist {
|
||||
list := Wishlist{
|
||||
Label: "Your todo list",
|
||||
}
|
||||
|
||||
if len(todo) < 1 {
|
||||
return list
|
||||
}
|
||||
|
||||
wishInputs := make([]Wish, len(todo))
|
||||
options := make([]hmc.Option, len(todo))
|
||||
|
||||
@ -144,36 +129,37 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
|
||||
options[i] = opt
|
||||
}
|
||||
|
||||
list.Wishes = &hmc.Form[Wishes]{
|
||||
Method: "POST",
|
||||
Elements: Wishes{
|
||||
Items: wishInputs,
|
||||
Select: hmc.Select{
|
||||
Label: "Todos",
|
||||
Multiple: true,
|
||||
Name: "todo",
|
||||
Required: true,
|
||||
Options: options,
|
||||
},
|
||||
Intent: hmc.Select{
|
||||
Label: "Intent",
|
||||
Required: true,
|
||||
Name: "intent",
|
||||
Options: []hmc.Option{
|
||||
{
|
||||
Label: "Unclaim",
|
||||
Value: "unclaim_todo",
|
||||
},
|
||||
{
|
||||
Label: "Complete",
|
||||
Value: "complete_todo",
|
||||
return Wishlist{
|
||||
Label: "Your todo list",
|
||||
Wishes: hmc.Form[Wishes]{
|
||||
Method: "POST",
|
||||
Elements: Wishes{
|
||||
Items: wishInputs,
|
||||
Select: hmc.Select{
|
||||
Label: "Todos",
|
||||
Multiple: true,
|
||||
Name: "todo",
|
||||
Required: true,
|
||||
Options: options,
|
||||
},
|
||||
Intent: hmc.Select{
|
||||
Label: "Intent",
|
||||
Required: true,
|
||||
Name: "intent",
|
||||
Options: []hmc.Option{
|
||||
{
|
||||
Label: "Unclaim",
|
||||
Value: "unclaim_todo",
|
||||
},
|
||||
{
|
||||
Label: "Complete",
|
||||
Value: "complete_todo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
func (w Wishlist) ExtractFormValues(form url.Values) {
|
||||
@ -181,10 +167,6 @@ 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()
|
||||
|
||||
@ -58,7 +58,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
|
||||
p := resources.HomeProps{
|
||||
Namespace: hmc.NS(),
|
||||
Navbar: navbar,
|
||||
Wishlist: resources.InitialWishlist(gifts),
|
||||
Wishlist: resources.InitialWishlist(user.Id, gifts),
|
||||
Todo: resources.InitialTodo(todo),
|
||||
GroupsList: resources.LinksList{
|
||||
Label: "Your groups",
|
||||
@ -90,7 +90,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
|
||||
p.Warning = "Extraneous form values"
|
||||
}
|
||||
|
||||
if p.Wishlist.Wishes != nil && p.Wishlist.Wishes.Elements.Intent.Value() == "delete" {
|
||||
if 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
|
||||
}
|
||||
}
|
||||
|
||||
if p.Todo.Wishes != nil && p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
|
||||
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
||||
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
||||
|
||||
if p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
|
||||
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 != nil && p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" {
|
||||
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
||||
} else if p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" {
|
||||
err := app.CompleteWishes(todosToChange)
|
||||
if err != nil {
|
||||
log.Printf("Failed to complete wish: %s\n", err)
|
||||
|
||||
@ -14,8 +14,7 @@
|
||||
<section class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h2>{{.Label}}</h2>
|
||||
{{with .Wishes}}
|
||||
{{with .Elements}}
|
||||
{{with .Wishes.Elements}}
|
||||
<form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off">
|
||||
<ul class="list-group mb-3">
|
||||
{{range .Items}}
|
||||
@ -31,7 +30,6 @@
|
||||
<button id="deleteSubmit" class="btn btn-danger mb-3" name="intent" value="delete"
|
||||
disabled>Delete</button>
|
||||
</form>
|
||||
{{end}}
|
||||
{{else}}
|
||||
<p>Your list is empty. Think of some things to add!</p>
|
||||
{{end}}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user