From 609ccfc0c4be94c35762f35a55ca4504989506b4 Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Mon, 8 Dec 2025 00:48:47 +0900 Subject: [PATCH] Navbar template --- http/api/register.go | 2 + http/response/response.go | 11 ++- http/routing/account.go | 4 +- http/routing/foreign_wishlist.go | 7 +- http/routing/groups.go | 16 +++-- http/routing/home.go | 17 ++--- http/templates/account.gotmpl | 38 +--------- http/templates/base.gotmpl | 72 ++++++++++++++----- http/templates/error_page.gotmpl | 23 +----- http/templates/foreign_wishlist.gotmpl | 38 +--------- http/templates/group_page.gotmpl | 38 +--------- http/templates/home.gotmpl | 41 +---------- http/templates/login.gotmpl | 14 +--- http/templates/public_foreign_wishlist.gotmpl | 21 +----- http/templates/public_group_page.gotmpl | 55 +++++--------- http/templates/register.gotmpl | 21 +----- http/templates/templates.go | 37 ++++++++++ 17 files changed, 164 insertions(+), 291 deletions(-) diff --git a/http/api/register.go b/http/api/register.go index c8e4301..debaa52 100644 --- a/http/api/register.go +++ b/http/api/register.go @@ -5,6 +5,7 @@ import ( ) type RegisterProps struct { + Navbar templates.NavCollapse GeneralError string `json:",omitempty"` Username templates.InputProps Password templates.InputProps @@ -36,6 +37,7 @@ func (p *RegisterProps) Validate() (valid bool) { func NewRegisterProps(usernameVal, passwordVal, confirmPassVal string) *RegisterProps { return &RegisterProps{ + Navbar: templates.DefaultNavCollapse(), GeneralError: "", Username: templates.InputProps{ Name: "username", diff --git a/http/response/response.go b/http/response/response.go index 8922d5b..5d53bf9 100644 --- a/http/response/response.go +++ b/http/response/response.go @@ -2,6 +2,7 @@ package response import ( "fmt" + "lishwist/http/templates" "net/http" "github.com/Teajey/rsvp" @@ -11,9 +12,17 @@ func NotFound() rsvp.Response { return Error(http.StatusNotFound, "Page not found") } +type errorProps struct { + Navbar templates.NavCollapse + Message string +} + func Error(status int, format string, a ...any) rsvp.Response { return rsvp.Response{ - Body: fmt.Sprintf(format, a...), + Body: errorProps{ + Message: fmt.Sprintf(format, a...), + Navbar: templates.DefaultNavCollapse(), + }, Status: status, TemplateName: "error_page.gotmpl", } diff --git a/http/routing/account.go b/http/routing/account.go index a469083..a6e163f 100644 --- a/http/routing/account.go +++ b/http/routing/account.go @@ -13,7 +13,7 @@ import ( ) type AccountProps struct { - CurrentUsername string + Navbar templates.NavCollapse GeneralError string `json:",omitempty"` PasswordFromAdmin bool `json:",omitempty"` Password templates.InputProps @@ -41,7 +41,7 @@ func (p *AccountProps) Validate() (valid bool) { func NewAccountProps(username string, passwordFromAdmin bool, passwordVal, confirmPassVal string) *AccountProps { return &AccountProps{ - CurrentUsername: username, + Navbar: templates.UserNavCollapse(username, false), PasswordFromAdmin: passwordFromAdmin, Password: templates.InputProps{ Type: "password", diff --git a/http/routing/foreign_wishlist.go b/http/routing/foreign_wishlist.go index 1162cf7..b8c00a9 100644 --- a/http/routing/foreign_wishlist.go +++ b/http/routing/foreign_wishlist.go @@ -3,6 +3,7 @@ package routing import ( lishwist "lishwist/core" "lishwist/http/response" + "lishwist/http/templates" "log" "net/http" @@ -10,6 +11,7 @@ import ( ) type foreignWishlistProps struct { + Navbar templates.NavCollapse CurrentUserId string CurrentUserName string Username string @@ -35,11 +37,12 @@ func ForeignWishlist(app *lishwist.Session, session *response.Session, h http.He log.Printf("%q couldn't get wishes of other user %q: %s\n", user.Name, otherUser.Name, err) return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(") } - p := foreignWishlistProps{CurrentUserId: user.Id, CurrentUserName: user.Name, Username: otherUser.Name, Gifts: wishes} + p := foreignWishlistProps{Navbar: templates.UserNavCollapse(user.Name, user.PasswordFromAdmin), CurrentUserId: user.Id, Username: otherUser.Name, Gifts: wishes} return response.Data("foreign_wishlist.gotmpl", p) } type publicWishlistProps struct { + Navbar templates.NavCollapse Username string GiftCount int } @@ -59,6 +62,6 @@ func PublicWishlist(s *response.Session, h http.Header, r *http.Request) rsvp.Re log.Printf("Couldn't get wishes of user %q on public wishlist: %s\n", otherUser.Name, err) return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(") } - p := publicWishlistProps{Username: otherUser.Name, GiftCount: giftCount} + p := publicWishlistProps{Navbar: templates.DefaultNavCollapse(), Username: otherUser.Name, GiftCount: giftCount} return response.Data("public_foreign_wishlist.gotmpl", p) } diff --git a/http/routing/groups.go b/http/routing/groups.go index a20a668..9ceaa2b 100644 --- a/http/routing/groups.go +++ b/http/routing/groups.go @@ -7,13 +7,14 @@ import ( lishwist "lishwist/core" "lishwist/http/response" + "lishwist/http/templates" "github.com/Teajey/rsvp" ) type GroupProps struct { - Group *lishwist.Group - CurrentUsername string + Navbar templates.NavCollapse + Group *lishwist.Group } func AdminGroup(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Response { @@ -31,8 +32,8 @@ func AdminGroup(app *lishwist.Session, h http.Header, r *http.Request) rsvp.Resp group.Members = slices.Delete(group.Members, index, index+1) } p := GroupProps{ - Group: group, - CurrentUsername: user.Name, + Navbar: templates.UserNavCollapse(user.Name, user.PasswordFromAdmin), + Group: group, } return response.Data("group_page.gotmpl", p) } @@ -54,8 +55,8 @@ func Group(app *lishwist.Session, session *response.Session, h http.Header, r *h index := group.MemberIndex(user.Id) group.Members = slices.Delete(group.Members, index, index+1) p := GroupProps{ - Group: group, - CurrentUsername: user.Name, + Navbar: templates.UserNavCollapse(user.Name, user.PasswordFromAdmin), + Group: group, } return response.Data("group_page.gotmpl", p) } @@ -71,7 +72,8 @@ func PublicGroup(s *response.Session, h http.Header, r *http.Request) rsvp.Respo return response.Error(http.StatusNotFound, "Group not found") } p := GroupProps{ - Group: group, + Navbar: templates.DefaultNavCollapse(), + Group: group, } return response.Data("public_group_page.gotmpl", p) } diff --git a/http/routing/home.go b/http/routing/home.go index bb41c11..334a992 100644 --- a/http/routing/home.go +++ b/http/routing/home.go @@ -7,18 +7,16 @@ import ( lishwist "lishwist/core" "lishwist/http/env" "lishwist/http/response" + "lishwist/http/templates" "github.com/Teajey/rsvp" ) type HomeProps struct { - Username string - Gifts []lishwist.Wish - Todo []lishwist.Wish - Reference string - HostUrl string - Groups []lishwist.Group - AccountAlert bool + Navbar templates.NavCollapse + Gifts []lishwist.Wish + Todo []lishwist.Wish + Groups []lishwist.Group } func Home(app *lishwist.Session, session *response.Session, h http.Header, r *http.Request) rsvp.Response { @@ -38,7 +36,10 @@ func Home(app *lishwist.Session, session *response.Session, h http.Header, r *ht log.Printf("Failed to get groups: %s\n", err) return response.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(") } - p := HomeProps{Username: user.Name, Gifts: gifts, Todo: todo, Reference: user.Reference, HostUrl: env.Configuration.HostUrl, Groups: groups, AccountAlert: user.PasswordFromAdmin} + p := HomeProps{Navbar: templates.NavCollapse{ + User: &templates.User{Name: user.Name, CopyList: &templates.CopyList{Domain: env.Configuration.HostUrl, Reference: user.Reference}}, + AccountLink: &templates.AccountLink{Alert: user.PasswordFromAdmin}, + }, Gifts: gifts, Todo: todo, Groups: groups} return response.Data("home.gotmpl", p) } diff --git a/http/templates/account.gotmpl b/http/templates/account.gotmpl index 88c56b4..dfd34b9 100644 --- a/http/templates/account.gotmpl +++ b/http/templates/account.gotmpl @@ -7,41 +7,7 @@