chore: remove accumulative balance in spaces page

This commit is contained in:
juancwu 2026-05-12 23:24:39 +00:00
commit c55de63f72
4 changed files with 8 additions and 58 deletions

View file

@ -78,15 +78,9 @@ func (h *spaceHandler) HomePage(w http.ResponseWriter, r *http.Request) {
ownedCards := h.buildSpaceCards(owned) ownedCards := h.buildSpaceCards(owned)
sharedCards := h.buildSpaceCards(shared) sharedCards := h.buildSpaceCards(shared)
total := decimal.Zero
for _, c := range ownedCards {
total = total.Add(c.TotalBalance)
}
ui.Render(w, r, pages.Home(pages.HomeProps{ ui.Render(w, r, pages.Home(pages.HomeProps{
OwnedSpaces: ownedCards, OwnedSpaces: ownedCards,
SharedSpaces: sharedCards, SharedSpaces: sharedCards,
TotalBalance: total,
})) }))
} }
@ -106,12 +100,7 @@ func (h *spaceHandler) SpacesPage(w http.ResponseWriter, r *http.Request) {
cards := h.buildSpaceCards(spaces) cards := h.buildSpaceCards(spaces)
total := decimal.Zero ui.Render(w, r, pages.Spaces(cards))
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) { func (h *spaceHandler) SharedSpacesPage(w http.ResponseWriter, r *http.Request) {
@ -141,22 +130,10 @@ func (h *spaceHandler) buildSpaceCards(spaces []*model.Space) []blocks.SpaceCard
memberCount = 0 memberCount = 0
} }
accounts, err := h.accountService.GetAccountsForSpace(sp.ID)
if err != nil {
slog.Error("failed to get space accounts", "error", err, "space_id", sp.ID)
accounts = nil
}
totalBalance := decimal.Zero
for _, acc := range accounts {
totalBalance = totalBalance.Add(acc.Balance)
}
cards = append(cards, blocks.SpaceCardInfo{ cards = append(cards, blocks.SpaceCardInfo{
ID: sp.ID, ID: sp.ID,
Name: sp.Name, Name: sp.Name,
MemberCount: memberCount, MemberCount: memberCount,
TotalBalance: totalBalance,
}) })
} }
return cards return cards

View file

@ -1,6 +1,5 @@
package blocks package blocks
import "github.com/shopspring/decimal"
import "strings" import "strings"
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon" import "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon"
import "fmt" import "fmt"
@ -10,7 +9,6 @@ type SpaceCardInfo struct {
ID string ID string
Name string Name string
MemberCount int MemberCount int
TotalBalance decimal.Decimal
} }
templ SpaceCard(info SpaceCardInfo) { templ SpaceCard(info SpaceCardInfo) {
@ -23,8 +21,6 @@ templ SpaceCard(info SpaceCardInfo) {
<div> <div>
<p class="font-semibold">{ info.Name }</p> <p class="font-semibold">{ info.Name }</p>
<p class="text-xs text-muted-foreground"> <p class="text-xs text-muted-foreground">
<span>${ info.TotalBalance.StringFixedBank(2) }</span>
<span>•</span>
<span>{ fmt.Sprintf("%d members", info.MemberCount) }</span> <span>{ fmt.Sprintf("%d members", info.MemberCount) }</span>
</p> </p>
</div> </div>

View file

@ -9,14 +9,11 @@ import (
"git.juancwu.dev/juancwu/budgit/internal/ui/components/button" "git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
"git.juancwu.dev/juancwu/budgit/internal/ui/components/icon" "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon"
"git.juancwu.dev/juancwu/budgit/internal/ui/layouts" "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
"git.juancwu.dev/juancwu/budgit/internal/ui/utils"
"github.com/shopspring/decimal"
) )
type HomeProps struct { type HomeProps struct {
OwnedSpaces []blocks.SpaceCardInfo OwnedSpaces []blocks.SpaceCardInfo
SharedSpaces []blocks.SpaceCardInfo SharedSpaces []blocks.SpaceCardInfo
TotalBalance decimal.Decimal
} }
templ Home(props HomeProps) { templ Home(props HomeProps) {
@ -36,14 +33,6 @@ templ Home(props HomeProps) {
<h1 class="text-2xl font-bold">Hello, { displayName }</h1> <h1 class="text-2xl font-bold">Hello, { displayName }</h1>
if totalSpaces == 0 { if totalSpaces == 0 {
<p class="text-muted-foreground">Create a space to start tracking your expenses.</p> <p class="text-muted-foreground">Create a space to start tracking your expenses.</p>
} else {
{{
countPhrase := fmt.Sprintf("Across %d spaces", totalSpaces)
if totalSpaces == 1 {
countPhrase = "Across 1 space"
}
}}
<p class="text-muted-foreground">{ countPhrase } you own you have <span class="font-medium text-foreground">${ utils.FormatDecimalWithThousands(props.TotalBalance.StringFixedBank(2)) }</span> tracked.</p>
} }
</div> </div>
<div> <div>

View file

@ -1,8 +1,6 @@
package pages package pages
import ( import (
"fmt"
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys" "git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
"git.juancwu.dev/juancwu/budgit/internal/routeurl" "git.juancwu.dev/juancwu/budgit/internal/routeurl"
"git.juancwu.dev/juancwu/budgit/internal/ui/blocks" "git.juancwu.dev/juancwu/budgit/internal/ui/blocks"
@ -10,11 +8,9 @@ import (
"git.juancwu.dev/juancwu/budgit/internal/ui/components/icon" "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/components/sidebar"
"git.juancwu.dev/juancwu/budgit/internal/ui/layouts" "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, totalBalance decimal.Decimal) { templ Spaces(spaces []blocks.SpaceCardInfo) {
{{ {{
user := ctxkeys.User(ctx) user := ctxkeys.User(ctx)
displayName := "" displayName := ""
@ -30,14 +26,6 @@ templ Spaces(spaces []blocks.SpaceCardInfo, totalBalance decimal.Decimal) {
<h1 class="text-2xl font-bold">Hello, { displayName }</h1> <h1 class="text-2xl font-bold">Hello, { displayName }</h1>
if len(spaces) == 0 { if len(spaces) == 0 {
<p class="text-muted-foreground">Create a space to start tracking your expenses.</p> <p class="text-muted-foreground">Create a space to start tracking your expenses.</p>
} else {
{{
countPhrase := fmt.Sprintf("Across %d spaces", len(spaces))
if len(spaces) == 1 {
countPhrase = "Across 1 space"
}
}}
<p class="text-muted-foreground">{ countPhrase } you have <span class="font-medium text-foreground">${ utils.FormatDecimalWithThousands(totalBalance.StringFixedBank(2)) }</span> tracked.</p>
} }
</div> </div>
<div> <div>