From 0e3b8159ff24dc872cdaf1c970ad89dbcdc33015 Mon Sep 17 00:00:00 2001 From: juancwu Date: Fri, 24 Apr 2026 00:26:23 +0000 Subject: [PATCH] refactor: spaces page header with greeting and handler-computed total Why: Move per-page balance summation out of the template (business logic belongs in the handler) and dedupe the pluralised summary copy while preserving the styled dollar span. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/handler/space.go | 8 +++++++- internal/ui/pages/spaces.templ | 34 ++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/internal/handler/space.go b/internal/handler/space.go index c314e85..dd55e66 100644 --- a/internal/handler/space.go +++ b/internal/handler/space.go @@ -50,7 +50,13 @@ func (h *spaceHandler) SpacesPage(w http.ResponseWriter, r *http.Request) { } cards := h.buildSpaceCards(spaces) - ui.Render(w, r, pages.Spaces(cards)) + + total := decimal.Zero + for _, c := range cards { + total = total.Add(c.TotalBalance) + } + + ui.Render(w, r, pages.Spaces(cards, total)) } func (h *spaceHandler) SharedSpacesPage(w http.ResponseWriter, r *http.Request) { diff --git a/internal/ui/pages/spaces.templ b/internal/ui/pages/spaces.templ index 821611e..88fa1f0 100644 --- a/internal/ui/pages/spaces.templ +++ b/internal/ui/pages/spaces.templ @@ -1,6 +1,8 @@ package pages import ( + "fmt" + "git.juancwu.dev/juancwu/budgit/internal/ctxkeys" "git.juancwu.dev/juancwu/budgit/internal/routeurl" "git.juancwu.dev/juancwu/budgit/internal/ui/blocks" @@ -8,15 +10,35 @@ import ( "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon" "git.juancwu.dev/juancwu/budgit/internal/ui/components/sidebar" "git.juancwu.dev/juancwu/budgit/internal/ui/layouts" + "git.juancwu.dev/juancwu/budgit/internal/ui/utils" + "github.com/shopspring/decimal" ) -templ Spaces(spaces []blocks.SpaceCardInfo) { - @layouts.App("Spaces", spaceOverviewSidebarContent()) { +templ Spaces(spaces []blocks.SpaceCardInfo, totalBalance decimal.Decimal) { + {{ + user := ctxkeys.User(ctx) + displayName := "" + if user != nil { + displayName = *user.Name + } + }} + @layouts.App("My Spaces", spaceOverviewSidebarContent()) {
-
-
-

My Spaces

-

Manage and monitor your expenses.

+
+
+

My Spaces

+

Good Evening, { displayName }

+ if len(spaces) == 0 { +

Create a space to start tracking your expenses.

+ } else { + {{ + countPhrase := fmt.Sprintf("Across %d spaces", len(spaces)) + if len(spaces) == 1 { + countPhrase = "Across 1 space" + } + }} +

{ countPhrase } you have ${ utils.FormatDecimalWithThousands(totalBalance.StringFixedBank(2)) } tracked.

+ }
@button.Button(button.Props{