Restore empty home page prompts

This commit is contained in:
Teajey 2026-11-18 00:03:04 +09:00
parent b5dfb135df
commit c7430bc942
No known key found for this signature in database
3 changed files with 74 additions and 58 deletions

View File

@ -37,11 +37,26 @@ 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(currentUserId string, wishes []lishwist.Wish) Wishlist {
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
}
wishInputs := make([]hmc.Option, len(wishes))
items := make([]Wish, len(wishes))
@ -62,9 +77,7 @@ func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
}
}
return Wishlist{
Label: "Your wishlist",
Wishes: hmc.Form[Wishes]{
list.Wishes = &hmc.Form[Wishes]{
Method: "POST",
Elements: Wishes{
Items: items,
@ -85,18 +98,20 @@ func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
}},
},
},
},
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))
@ -129,9 +144,7 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
options[i] = opt
}
return Wishlist{
Label: "Your todo list",
Wishes: hmc.Form[Wishes]{
list.Wishes = &hmc.Form[Wishes]{
Method: "POST",
Elements: Wishes{
Items: wishInputs,
@ -158,8 +171,9 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
},
},
},
},
}
return list
}
func (w Wishlist) ExtractFormValues(form url.Values) {

View File

@ -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(user.Id, gifts),
Wishlist: resources.InitialWishlist(gifts),
Todo: resources.InitialTodo(todo),
GroupsList: resources.LinksList{
Label: "Your groups",

View File

@ -14,7 +14,8 @@
<section class="card mb-4">
<div class="card-body">
<h2>{{.Label}}</h2>
{{with .Wishes.Elements}}
{{with .Wishes}}
{{with .Elements}}
<form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off">
<ul class="list-group mb-3">
{{range .Items}}
@ -30,6 +31,7 @@
<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}}