feat(period): everything preset from the first transaction date

This commit is contained in:
hh committed 2026-10-16 02:36:16 +00:00
1 parent c27da77aab
commit 135a2d9328
2 files changed
+19

No files matched your search

+18
View File
@@ -1,3 +1,5 @@
import { api } from "#lib/api/client.js";
import type { Page, TransactionGroup } from "#lib/api/types.js";
import {
addDays,
isDynamic,
@@ -70,6 +72,22 @@ class Period {
this.ready = true;
}
async loadFirst() {
const query = { end: today(), limit: 1, start: "1970-01-02", type: "all" };
const head = await api<Page<TransactionGroup>>("/v1/transactions", {
query,
});
const pages = head.meta.pagination?.total_pages ?? 0;
if (pages === 0) {
return;
}
const last = await api<Page<TransactionGroup>>("/v1/transactions", {
query: { ...query, page: pages },
});
const date = last.data[0]?.attributes.transactions[0]?.date;
this.first = date ? date.slice(0, 10) : null;
}
set(range: Range) {
if (range.start === this.start && range.end === this.end) {
return;
+1
View File
@@ -20,6 +20,7 @@
try {
const back = await session.boot();
period.init(session.viewRange, page.url);
period.loadFirst().catch(() => undefined);
if (back) {
await goto(back, { replace: true });
}