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)
|
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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user