feat(period): everything preset from the first transaction date
This commit is contained in:
1 parent
c27da77aab
commit
135a2d9328
2 files changed
+19
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
import { api } from "#lib/api/client.js";
|
||||||
|
import type { Page, TransactionGroup } from "#lib/api/types.js";
|
||||||
import {
|
import {
|
||||||
addDays,
|
addDays,
|
||||||
isDynamic,
|
isDynamic,
|
||||||
@@ -70,6 +72,22 @@ class Period {
|
|||||||
this.ready = true;
|
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) {
|
set(range: Range) {
|
||||||
if (range.start === this.start && range.end === this.end) {
|
if (range.start === this.start && range.end === this.end) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
try {
|
try {
|
||||||
const back = await session.boot();
|
const back = await session.boot();
|
||||||
period.init(session.viewRange, page.url);
|
period.init(session.viewRange, page.url);
|
||||||
|
period.loadFirst().catch(() => undefined);
|
||||||
if (back) {
|
if (back) {
|
||||||
await goto(back, { replace: true });
|
await goto(back, { replace: true });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user