feat: global time range context with custom date picker

Lift time range state into a shared React context so the selected
range persists across page navigation and browser refreshes
(localStorage). Add a "Custom" option with a popover date picker
that lets users specify arbitrary start/end dates. All preset end
times now use endOf("day") (23:59:59) instead of the current moment.
This commit is contained in:
2026-04-07 14:49:58 +08:00
parent 004fd37622
commit 9bb36432ba
10 changed files with 280 additions and 55 deletions

View File

@@ -27,13 +27,14 @@ export type TimeRange = "today" | "7d" | "30d" | "all" | "custom";
export function getTimeRange(range: TimeRange): { start?: number; end?: number } {
const now = dayjs();
const end = now.endOf("day").unix();
switch (range) {
case "today":
return { start: now.startOf("day").unix(), end: now.unix() };
return { start: now.startOf("day").unix(), end };
case "7d":
return { start: now.subtract(7, "day").startOf("day").unix(), end: now.unix() };
return { start: now.subtract(7, "day").startOf("day").unix(), end };
case "30d":
return { start: now.subtract(30, "day").startOf("day").unix(), end: now.unix() };
return { start: now.subtract(30, "day").startOf("day").unix(), end };
case "all":
return {};
default: