feat(dashboard): #163 first summary
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"spend-sparrow/internal/template"
|
||||
"spend-sparrow/internal/template/dashboard"
|
||||
"spend-sparrow/internal/types"
|
||||
"spend-sparrow/internal/utils"
|
||||
"time"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
@@ -41,6 +42,8 @@ func (handler IndexImpl) handleRootAnd404() http.HandlerFunc {
|
||||
|
||||
user := middleware.GetUser(r)
|
||||
|
||||
htmx := utils.IsHtmx(r)
|
||||
|
||||
var comp templ.Component
|
||||
|
||||
var status int
|
||||
@@ -50,7 +53,7 @@ func (handler IndexImpl) handleRootAnd404() http.HandlerFunc {
|
||||
} else {
|
||||
if user != nil {
|
||||
var err error
|
||||
comp, err = handler.dashboard(user, r)
|
||||
comp, err = handler.dashboard(user, htmx, r)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get dashboard summary", "err", err)
|
||||
}
|
||||
@@ -60,17 +63,21 @@ func (handler IndexImpl) handleRootAnd404() http.HandlerFunc {
|
||||
status = http.StatusOK
|
||||
}
|
||||
|
||||
handler.r.RenderLayoutWithStatus(r, w, comp, user, status)
|
||||
if htmx {
|
||||
handler.r.RenderWithStatus(r, w, comp, status)
|
||||
} else {
|
||||
handler.r.RenderLayoutWithStatus(r, w, comp, user, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (handler IndexImpl) dashboard(user *types.User, r *http.Request) (templ.Component, error) {
|
||||
func (handler IndexImpl) dashboard(user *types.User, htmx bool, r *http.Request) (templ.Component, error) {
|
||||
|
||||
var month time.Time
|
||||
var err error
|
||||
monthStr := r.URL.Query().Get("month")
|
||||
if monthStr != "" {
|
||||
month, err = time.Parse("2006-01-02", r.FormValue("timestamp"))
|
||||
month, err = time.Parse("2006-01-02", monthStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse timestamp: %w", service.ErrBadRequest)
|
||||
}
|
||||
@@ -83,8 +90,11 @@ func (handler IndexImpl) dashboard(user *types.User, r *http.Request) (templ.Com
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comp := dashboard.Dashboard(summary)
|
||||
return comp, nil
|
||||
if htmx {
|
||||
return dashboard.DashboardData(summary), nil
|
||||
} else {
|
||||
return dashboard.Dashboard(summary), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (handler IndexImpl) handleEmpty() http.HandlerFunc {
|
||||
|
||||
Reference in New Issue
Block a user