From c7430bc9422d314daf2755cb95eda222d6cc0b19 Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:03:04 +0900 Subject: [PATCH] Restore empty home page prompts --- http/resources/home.go | 126 ++++++++++++++++++++----------------- http/routing/home.go | 2 +- http/templates/home.gotmpl | 4 +- 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/http/resources/home.go b/http/resources/home.go index 64bab47..ea3f1b8 100644 --- a/http/resources/home.go +++ b/http/resources/home.go @@ -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,41 +77,41 @@ func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist { } } - 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", - }}, - }, + list.Wishes = &hmc.Form[Wishes]{ + Method: "POST", + Elements: Wishes{ + Items: items, + Select: hmc.Select{ + Label: "Wishes", + Multiple: true, + Name: "wish", + Required: true, + Options: wishInputs, }, - }, - NewWish: &hmc.Form[hmc.Input]{ - Method: "POST", - Elements: hmc.Input{ - Label: "Add gift idea", - Name: "gift_name", + Intent: hmc.Select{ + Label: "Intent", + Required: true, + Name: "intent", + Options: []hmc.Option{{ + Label: "Delete", + Value: "delete", + }}, }, }, } + + 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,37 +144,36 @@ func InitialTodo(todo []lishwist.Wish) Wishlist { options[i] = opt } - 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", - }, + 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) { diff --git a/http/routing/home.go b/http/routing/home.go index ff7392d..354eaeb 100644 --- a/http/routing/home.go +++ b/http/routing/home.go @@ -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", diff --git a/http/templates/home.gotmpl b/http/templates/home.gotmpl index 90eb927..fa4f016 100644 --- a/http/templates/home.gotmpl +++ b/http/templates/home.gotmpl @@ -14,7 +14,8 @@

{{.Label}}

- {{with .Wishes.Elements}} + {{with .Wishes}} + {{with .Elements}}
    {{range .Items}} @@ -30,6 +31,7 @@ + {{end}} {{else}}

    Your list is empty. Think of some things to add!

    {{end}}