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 { type Wishlist struct {
Label string `json:"label" xml:",chardata"` 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"` 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)) wishInputs := make([]hmc.Option, len(wishes))
items := make([]Wish, len(wishes)) items := make([]Wish, len(wishes))
@ -62,9 +77,7 @@ func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
} }
} }
return Wishlist{ list.Wishes = &hmc.Form[Wishes]{
Label: "Your wishlist",
Wishes: hmc.Form[Wishes]{
Method: "POST", Method: "POST",
Elements: Wishes{ Elements: Wishes{
Items: items, 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 { func InitialTodo(todo []lishwist.Wish) Wishlist {
list := Wishlist{
Label: "Your todo list",
}
if len(todo) < 1 {
return list
}
wishInputs := make([]Wish, len(todo)) wishInputs := make([]Wish, len(todo))
options := make([]hmc.Option, len(todo)) options := make([]hmc.Option, len(todo))
@ -129,9 +144,7 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
options[i] = opt options[i] = opt
} }
return Wishlist{ list.Wishes = &hmc.Form[Wishes]{
Label: "Your todo list",
Wishes: hmc.Form[Wishes]{
Method: "POST", Method: "POST",
Elements: Wishes{ Elements: Wishes{
Items: wishInputs, Items: wishInputs,
@ -158,8 +171,9 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
}, },
}, },
}, },
},
} }
return list
} }
func (w Wishlist) ExtractFormValues(form url.Values) { 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{ p := resources.HomeProps{
Namespace: hmc.NS(), Namespace: hmc.NS(),
Navbar: navbar, Navbar: navbar,
Wishlist: resources.InitialWishlist(user.Id, gifts), Wishlist: resources.InitialWishlist(gifts),
Todo: resources.InitialTodo(todo), Todo: resources.InitialTodo(todo),
GroupsList: resources.LinksList{ GroupsList: resources.LinksList{
Label: "Your groups", Label: "Your groups",

View File

@ -14,7 +14,8 @@
<section class="card mb-4"> <section class="card mb-4">
<div class="card-body"> <div class="card-body">
<h2>{{.Label}}</h2> <h2>{{.Label}}</h2>
{{with .Wishes.Elements}} {{with .Wishes}}
{{with .Elements}}
<form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off"> <form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off">
<ul class="list-group mb-3"> <ul class="list-group mb-3">
{{range .Items}} {{range .Items}}
@ -30,6 +31,7 @@
<button id="deleteSubmit" class="btn btn-danger mb-3" name="intent" value="delete" <button id="deleteSubmit" class="btn btn-danger mb-3" name="intent" value="delete"
disabled>Delete</button> disabled>Delete</button>
</form> </form>
{{end}}
{{else}} {{else}}
<p>Your list is empty. Think of some things to add!</p> <p>Your list is empty. Think of some things to add!</p>
{{end}} {{end}}