Skip to content

Commit efaed52

Browse files
wip: date range modal / prev / next
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 1a753aa commit efaed52

File tree

11 files changed

+211
-59
lines changed

11 files changed

+211
-59
lines changed

Cargo.lock

Lines changed: 62 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bun.lockb

-51.9 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

web/bun.lockb

-3.09 KB
Binary file not shown.

web/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
"@radix-ui/react-accordion": "^1.2.1",
1919
"@radix-ui/react-dialog": "^1.1.2",
2020
"@radix-ui/react-tabs": "^1.1.1",
21-
"@scaleway/use-query-params": "^5.0.8",
22-
"@tanstack/react-query": "^5.59.20",
21+
"@tanstack/react-query": "^5.60.5",
2322
"@uidotdev/usehooks": "^2.4.1",
2423
"date-fns": "^4.1.0",
25-
"fets": "^0.8.3",
24+
"fets": "^0.8.4",
2625
"fuzzysort": "^3.1.0",
2726
"lightningcss": "^1.28.1",
28-
"lucide-react": "^0.456.0",
27+
"little-date": "^1.0.0",
28+
"lucide-react": "^0.460.0",
2929
"react": "^18.3.1",
3030
"react-dom": "^18.3.1",
3131
"react-simple-maps": "^3.0.0",
@@ -37,7 +37,7 @@
3737
"@types/react": "^18.3.12",
3838
"@types/react-dom": "^18.3.1",
3939
"@types/react-simple-maps": "^3.0.6",
40-
"astro": "^4.16.10",
40+
"astro": "^4.16.13",
4141
"bun-types": "^1.1.34",
4242
"rollup-plugin-license": "^3.5.3",
4343
"typescript": "^5.6.3"

web/src/api/ranges.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
differenceInMonths,
66
endOfDay,
77
endOfHour,
8+
endOfYear,
89
startOfDay,
910
startOfMonth,
1011
startOfYear,
1112
subDays,
1213
subMonths,
14+
subYears,
1315
} from "date-fns";
1416

1517
import type { DateRange } from "./types";
@@ -111,3 +113,27 @@ export const ranges: Record<RangeName, () => { range: DateRange; dataPoints: num
111113
return { range: { start, end: now }, dataPoints: months + 1, graphRange: "month" };
112114
},
113115
};
116+
117+
export const previusRange = (range: string) => {
118+
if (range === "today") return "yesterday";
119+
if (range === "yearToDate") {
120+
const lastYear = subYears(new Date(), 1);
121+
const start = startOfYear(lastYear).getTime();
122+
const end = endOfYear(lastYear).getTime();
123+
return serializeRange({ start, end });
124+
}
125+
const r = deserializeRange(range);
126+
const size = r.end - r.start;
127+
const start = r.start - size;
128+
const end = r.end - size;
129+
return serializeRange({ start: startOfDay(start).getTime(), end: endOfDay(end).getTime() });
130+
};
131+
132+
export const nextRange = (range: string) => {
133+
if (range === "yesterday") return "today";
134+
const r = deserializeRange(range);
135+
const size = r.end - r.start;
136+
const start = r.start + size;
137+
const end = r.end + size;
138+
return serializeRange({ start: startOfDay(start).getTime(), end: endOfDay(end).getTime() });
139+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.container {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
}

0 commit comments

Comments
 (0)