fix(dashboard): #163 month selection on first load
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m54s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 4m56s

This commit was merged in pull request #183.
This commit is contained in:
2025-06-16 12:52:49 +02:00
parent 6b8059889d
commit 3df9fab25b
6 changed files with 8 additions and 8 deletions

View File

@@ -119,7 +119,7 @@ func createHandler(d *sqlx.DB, serverSettings *types.Settings) http.Handler {
dashboardService := service.NewDashboard(d) dashboardService := service.NewDashboard(d)
render := handler.NewRender() render := handler.NewRender()
indexHandler := handler.NewIndex(render, dashboardService) indexHandler := handler.NewIndex(render, dashboardService, clockService)
authHandler := handler.NewAuth(authService, render) authHandler := handler.NewAuth(authService, render)
accountHandler := handler.NewAccount(accountService, render) accountHandler := handler.NewAccount(accountService, render)
treasureChestHandler := handler.NewTreasureChest(treasureChestService, transactionRecurringService, render) treasureChestHandler := handler.NewTreasureChest(treasureChestService, transactionRecurringService, render)

View File

@@ -22,12 +22,14 @@ type Index interface {
type IndexImpl struct { type IndexImpl struct {
r *Render r *Render
d *service.Dashboard d *service.Dashboard
c service.Clock
} }
func NewIndex(r *Render, d *service.Dashboard) Index { func NewIndex(r *Render, d *service.Dashboard, c service.Clock) Index {
return IndexImpl{ return IndexImpl{
r: r, r: r,
d: d, d: d,
c: c,
} }
} }
@@ -81,7 +83,7 @@ func (handler IndexImpl) dashboard(user *types.User, htmx bool, r *http.Request)
return nil, fmt.Errorf("could not parse timestamp: %w", service.ErrBadRequest) return nil, fmt.Errorf("could not parse timestamp: %w", service.ErrBadRequest)
} }
} else { } else {
month = time.Now() month = handler.c.Now()
} }
summary, err := handler.d.Summary(r.Context(), user, month) summary, err := handler.d.Summary(r.Context(), user, month)

View File

@@ -13,5 +13,5 @@ func NewClock() Clock {
} }
func (c *ClockImpl) Now() time.Time { func (c *ClockImpl) Now() time.Time {
return time.Now() return time.Now().UTC()
} }

View File

@@ -2,7 +2,6 @@ package service
import ( import (
"context" "context"
"log/slog"
"spend-sparrow/internal/db" "spend-sparrow/internal/db"
"spend-sparrow/internal/types" "spend-sparrow/internal/types"
"time" "time"
@@ -82,7 +81,5 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
summary.Total = summary.Income + summary.Expenses summary.Total = summary.Income + summary.Expenses
summary.Month = month summary.Month = month
slog.Info("Dashboard summary", "summary", summary)
return &summary, nil return &summary, nil
} }

View File

@@ -9,7 +9,7 @@ templ Dashboard(summary *types.DashboardMonthlySummary) {
<input <input
name="month" name="month"
type="date" type="date"
class="input" class="input datetime"
value={ summary.Month.String() } value={ summary.Month.String() }
/> />
</form> </form>

View File

@@ -17,6 +17,7 @@ function updateTime() {
const newDate = value.includes("UTC") ? new Date(value) : value; const newDate = value.includes("UTC") ? new Date(value) : value;
el.valueAsDate = newDate; el.valueAsDate = newDate;
} }
el.classList.remove("datetime");
}) })
} }