fix: Net Worth defaults to 5y, Dashboard->Transactions keeps month/year

Net Worth opened on a 30-day window by default, which frequently shows
a dip (short windows don't have enough recorded income relative to
spending) even though the long-term trend is a steady climb —
demotivating for no good reason. Defaults to 5y instead.

Dashboard's "All transactions" link always sent users to the current
month regardless of which month they had selected. It now carries
?year=&month= and TransactionsPage seeds its state from those params
(clamped/validated, falls back to the current month if absent).
This commit is contained in:
ZProger
2026-08-16 22:31:10 +03:00
parent 5b42e3d972
commit 98c61d50d8
4 changed files with 28 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "aurum-frontend",
"private": true,
"version": "0.17.0",
"version": "0.17.1",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -18,7 +18,10 @@ export function RecentTransactionsCard({ year, month }: RecentTransactionsCardPr
<Card>
<CardHeader>
<CardTitle>{t("dashboard.recentTransactionsTitle")}</CardTitle>
<Link to="/transactions" className="text-xs font-medium text-series-1 hover:underline">
<Link
to={`/transactions?year=${year}&month=${month}`}
className="text-xs font-medium text-series-1 hover:underline"
>
{t("dashboard.allTransactionsLink")}
</Link>
</CardHeader>

View File

@@ -16,7 +16,10 @@ import type { Asset, NetWorthRange } from "@/types";
export function NetWorthPage() {
const { t } = useTranslation();
const [range, setRange] = useState<NetWorthRange>("30d");
// Defaults to 5 years: a short window can show a dip whenever spending
// briefly outpaces recorded income, which reads as decline even though
// the long-run trend is up — 5y is long enough to make that trend visible.
const [range, setRange] = useState<NetWorthRange>("5y");
const { data: summary, isLoading: isSummaryLoading } = useNetWorthSummary(range);
const { data: assets, isLoading: isAssetsLoading } = useAssets();
const deleteAsset = useDeleteAsset();

View File

@@ -1,4 +1,5 @@
import { useState } from "react";
import { useSearchParams } from "react-router-dom";
import { Plus } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
import { Button } from "@/components/ui/Button";
@@ -16,11 +17,27 @@ import type { Transaction, TransactionType } from "@/types";
const PAGE_SIZE = 20;
/** Clamp a query-param month to 1-12, falling back to `fallback` for
* anything missing or out of range (e.g. a hand-edited URL). */
function parseMonthParam(value: string | null, fallback: number): number {
const parsed = Number(value);
return Number.isInteger(parsed) ? Math.min(12, Math.max(1, parsed)) : fallback;
}
function parseYearParam(value: string | null, fallback: number): number {
const parsed = Number(value);
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
}
export function TransactionsPage() {
const { t } = useTranslation();
const now = new Date();
const [year, setYear] = useState(now.getFullYear());
const [month, setMonth] = useState(now.getMonth() + 1);
// Deep-linked from the Dashboard's "All transactions" link, which carries
// the month/year the user was already looking at (?year=&month=) so this
// page doesn't reset back to the current month.
const [searchParams] = useSearchParams();
const [year, setYear] = useState(() => parseYearParam(searchParams.get("year"), now.getFullYear()));
const [month, setMonth] = useState(() => parseMonthParam(searchParams.get("month"), now.getMonth() + 1));
const [type, setType] = useState<TransactionType | "">("");
const [categoryId, setCategoryId] = useState<string>("");
const [sort, setSort] = useState<TransactionSort>("date_desc");