fix: reports date range active state does not update
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m22s

This commit is contained in:
juancwu 2026-02-15 23:08:03 +00:00
commit 03217ac69f
2 changed files with 32 additions and 33 deletions

View file

@ -2150,8 +2150,7 @@ func (h *SpaceHandler) GetReportCharts(w http.ResponseWriter, r *http.Request) {
return
}
_ = activeRange
ui.Render(w, r, pages.ReportCharts(spaceID, report, from, to))
ui.Render(w, r, pages.ReportCharts(spaceID, report, from, to, presets, activeRange))
}
func (h *SpaceHandler) buildListCards(spaceID string) ([]model.ListCardData, error) {

View file

@ -28,43 +28,43 @@ templ SpaceReportsPage(space *model.Space, report *model.SpendingReport, presets
@chart.Script()
<div class="space-y-4">
<h1 class="text-2xl font-bold">Reports</h1>
// Date range selector
<div class="flex flex-wrap gap-2 items-center">
for _, p := range presets {
if p.Key == activeRange {
@button.Button(button.Props{
Size: button.SizeSm,
Attributes: templ.Attributes{
"hx-get": fmt.Sprintf("/app/spaces/%s/components/report-charts?range=%s", space.ID, p.Key),
"hx-target": "#report-content",
"hx-swap": "innerHTML",
},
}) {
{ p.Label }
}
} else {
@button.Button(button.Props{
Variant: button.VariantOutline,
Size: button.SizeSm,
Attributes: templ.Attributes{
"hx-get": fmt.Sprintf("/app/spaces/%s/components/report-charts?range=%s", space.ID, p.Key),
"hx-target": "#report-content",
"hx-swap": "innerHTML",
},
}) {
{ p.Label }
}
}
}
</div>
<div id="report-content">
@ReportCharts(space.ID, report, presets[0].From, presets[0].To)
@ReportCharts(space.ID, report, presets[0].From, presets[0].To, presets, activeRange)
</div>
</div>
}
}
templ ReportCharts(spaceID string, report *model.SpendingReport, from, to time.Time) {
templ ReportCharts(spaceID string, report *model.SpendingReport, from, to time.Time, presets []service.DateRange, activeRange string) {
// Date range selector
<div class="flex flex-wrap gap-2 items-center mb-4">
for _, p := range presets {
if p.Key == activeRange {
@button.Button(button.Props{
Size: button.SizeSm,
Attributes: templ.Attributes{
"hx-get": fmt.Sprintf("/app/spaces/%s/components/report-charts?range=%s", spaceID, p.Key),
"hx-target": "#report-content",
"hx-swap": "innerHTML",
},
}) {
{ p.Label }
}
} else {
@button.Button(button.Props{
Variant: button.VariantOutline,
Size: button.SizeSm,
Attributes: templ.Attributes{
"hx-get": fmt.Sprintf("/app/spaces/%s/components/report-charts?range=%s", spaceID, p.Key),
"hx-target": "#report-content",
"hx-swap": "innerHTML",
},
}) {
{ p.Label }
}
}
}
</div>
<div class="grid gap-4 md:grid-cols-2 overflow-hidden">
// Income vs Expenses Summary
<div class="border rounded-lg p-4 bg-card text-card-foreground space-y-2 min-w-0">