feat: add day/week/month period toggle for dashboard line charts

Add a period selector (day, week, month) to the reading activity and
books added charts. The API now accepts a ?period= query param and
returns gap-filled data using generate_series so all time slots appear
even with zero values. Labels are locale-aware (short month, weekday).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 10:27:24 +01:00
parent 6f663eaee7
commit cf1953d11f
6 changed files with 259 additions and 57 deletions

View File

@@ -584,8 +584,9 @@ export type StatsResponse = {
metadata: MetadataStats;
};
export async function fetchStats() {
return apiFetch<StatsResponse>("/stats", { next: { revalidate: 30 } });
export async function fetchStats(period?: "day" | "week" | "month") {
const params = period && period !== "month" ? `?period=${period}` : "";
return apiFetch<StatsResponse>(`/stats${params}`, { next: { revalidate: 30 } });
}
// ---------------------------------------------------------------------------