From 98c61d50d87ef3dc87da77ed53b07c9cec0cefdb Mon Sep 17 00:00:00 2001 From: ZProger Date: Sun, 16 Aug 2026 22:31:10 +0300 Subject: [PATCH] fix: Net Worth defaults to 5y, Dashboard->Transactions keeps month/year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- frontend/package.json | 2 +- .../dashboard/RecentTransactionsCard.tsx | 5 ++++- frontend/src/pages/NetWorthPage.tsx | 5 ++++- frontend/src/pages/TransactionsPage.tsx | 21 +++++++++++++++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index b05dbeb..b8994c3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "aurum-frontend", "private": true, - "version": "0.17.0", + "version": "0.17.1", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/components/dashboard/RecentTransactionsCard.tsx b/frontend/src/components/dashboard/RecentTransactionsCard.tsx index daf2a86..f2ffc43 100644 --- a/frontend/src/components/dashboard/RecentTransactionsCard.tsx +++ b/frontend/src/components/dashboard/RecentTransactionsCard.tsx @@ -18,7 +18,10 @@ export function RecentTransactionsCard({ year, month }: RecentTransactionsCardPr {t("dashboard.recentTransactionsTitle")} - + {t("dashboard.allTransactionsLink")} diff --git a/frontend/src/pages/NetWorthPage.tsx b/frontend/src/pages/NetWorthPage.tsx index 50103fa..04f8825 100644 --- a/frontend/src/pages/NetWorthPage.tsx +++ b/frontend/src/pages/NetWorthPage.tsx @@ -16,7 +16,10 @@ import type { Asset, NetWorthRange } from "@/types"; export function NetWorthPage() { const { t } = useTranslation(); - const [range, setRange] = useState("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("5y"); const { data: summary, isLoading: isSummaryLoading } = useNetWorthSummary(range); const { data: assets, isLoading: isAssetsLoading } = useAssets(); const deleteAsset = useDeleteAsset(); diff --git a/frontend/src/pages/TransactionsPage.tsx b/frontend/src/pages/TransactionsPage.tsx index 552dabe..d104da0 100644 --- a/frontend/src/pages/TransactionsPage.tsx +++ b/frontend/src/pages/TransactionsPage.tsx @@ -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(""); const [categoryId, setCategoryId] = useState(""); const [sort, setSort] = useState("date_desc");