feat: new home page

This commit is contained in:
juancwu 2026-05-03 23:02:51 +00:00
commit 145eed9eef
7 changed files with 142 additions and 3 deletions

View file

@ -21,7 +21,7 @@ func (h *homeHandler) HomePage(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/auth", http.StatusSeeOther)
return
}
http.Redirect(w, r, "/app/spaces", http.StatusSeeOther)
http.Redirect(w, r, "/app/home", http.StatusSeeOther)
}
func (h *homeHandler) PrivacyPage(w http.ResponseWriter, r *http.Request) {

View file

@ -9,5 +9,5 @@ func NewRedirectHandler() *redirectHandler {
}
func (h *redirectHandler) Spaces(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/app/spaces", http.StatusMovedPermanently)
http.Redirect(w, r, "/app/home", http.StatusMovedPermanently)
}

View file

@ -17,5 +17,5 @@ func TestRedirectHandler_RederictToSpaces(t *testing.T) {
h.Spaces(w, req)
assert.Equal(t, http.StatusMovedPermanently, w.Code)
assert.Equal(t, "/app/spaces", w.Header().Get("Location"))
assert.Equal(t, "/app/home", w.Header().Get("Location"))
}

View file

@ -41,6 +41,42 @@ func NewSpaceHandler(
}
}
func (h *spaceHandler) HomePage(w http.ResponseWriter, r *http.Request) {
user := ctxkeys.User(r.Context())
if user == nil {
ui.RenderError(w, r, "Unauthorized", http.StatusUnauthorized)
return
}
owned, err := h.spaceService.GetOwnedSpaces(user.ID)
if err != nil {
slog.Error("failed to load owned spaces", "error", err, "user_id", user.ID)
ui.RenderError(w, r, "Failed to load spaces", http.StatusInternalServerError)
return
}
shared, err := h.spaceService.GetSharedSpaces(user.ID)
if err != nil {
slog.Error("failed to load shared spaces", "error", err, "user_id", user.ID)
ui.RenderError(w, r, "Failed to load spaces", http.StatusInternalServerError)
return
}
ownedCards := h.buildSpaceCards(owned)
sharedCards := h.buildSpaceCards(shared)
total := decimal.Zero
for _, c := range ownedCards {
total = total.Add(c.TotalBalance)
}
ui.Render(w, r, pages.Home(pages.HomeProps{
OwnedSpaces: ownedCards,
SharedSpaces: sharedCards,
TotalBalance: total,
}))
}
func (h *spaceHandler) SpacesPage(w http.ResponseWriter, r *http.Request) {
user := ctxkeys.User(r.Context())
if user == nil {