fix(dashboard): #163 month selection on first load
This commit was merged in pull request #183.
This commit is contained in:
@@ -119,7 +119,7 @@ func createHandler(d *sqlx.DB, serverSettings *types.Settings) http.Handler {
|
||||
dashboardService := service.NewDashboard(d)
|
||||
|
||||
render := handler.NewRender()
|
||||
indexHandler := handler.NewIndex(render, dashboardService)
|
||||
indexHandler := handler.NewIndex(render, dashboardService, clockService)
|
||||
authHandler := handler.NewAuth(authService, render)
|
||||
accountHandler := handler.NewAccount(accountService, render)
|
||||
treasureChestHandler := handler.NewTreasureChest(treasureChestService, transactionRecurringService, render)
|
||||
|
||||
@@ -22,12 +22,14 @@ type Index interface {
|
||||
type IndexImpl struct {
|
||||
r *Render
|
||||
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{
|
||||
r: r,
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
month = time.Now()
|
||||
month = handler.c.Now()
|
||||
}
|
||||
|
||||
summary, err := handler.d.Summary(r.Context(), user, month)
|
||||
|
||||
@@ -13,5 +13,5 @@ func NewClock() Clock {
|
||||
}
|
||||
|
||||
func (c *ClockImpl) Now() time.Time {
|
||||
return time.Now()
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"spend-sparrow/internal/db"
|
||||
"spend-sparrow/internal/types"
|
||||
"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.Month = month
|
||||
|
||||
slog.Info("Dashboard summary", "summary", summary)
|
||||
|
||||
return &summary, nil
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ templ Dashboard(summary *types.DashboardMonthlySummary) {
|
||||
<input
|
||||
name="month"
|
||||
type="date"
|
||||
class="input"
|
||||
class="input datetime"
|
||||
value={ summary.Month.String() }
|
||||
/>
|
||||
</form>
|
||||
|
||||
@@ -17,6 +17,7 @@ function updateTime() {
|
||||
const newDate = value.includes("UTC") ? new Date(value) : value;
|
||||
el.valueAsDate = newDate;
|
||||
}
|
||||
el.classList.remove("datetime");
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user