Skip to content

Commit 5f88dcd

Browse files
committed
chore: replace static description with dynamic timeframe label
1 parent 9e07cf7 commit 5f88dcd

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/app/dashboard/performance/net-worth-history/Chart.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { APP_CURRENCY } from "~/constants";
2525
import { calculateZeroInclusiveYAxisDomain } from "~/utils/chart";
2626
import { formatDate } from "~/utils/date";
2727
import { formatNumber } from "~/utils/number";
28+
import { Timeframe } from "./page";
2829

2930
type ChartDataItem = {
3031
id: string;
@@ -49,7 +50,13 @@ const netWorthChartConfig: ChartConfig = {
4950
},
5051
};
5152

52-
export function Chart({ data }: { data: ChartDataItem[] }) {
53+
export function Chart({
54+
data,
55+
selectedTimeframe,
56+
}: {
57+
data: ChartDataItem[];
58+
selectedTimeframe: Timeframe;
59+
}) {
5360
const chartData = data.map((nw) => ({
5461
month: formatDate({
5562
date: nw.timestamp,
@@ -68,7 +75,7 @@ export function Chart({ data }: { data: ChartDataItem[] }) {
6875
<Card>
6976
<CardHeader>
7077
<CardTitle>Net worth history</CardTitle>
71-
<CardDescription>All time</CardDescription>
78+
<CardDescription>{selectedTimeframe.label}</CardDescription>
7279
</CardHeader>
7380
<CardContent>
7481
<ChartContainer

src/app/dashboard/performance/net-worth-history/page.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { isAfter, subYears } from "date-fns";
3030

3131
type Tab = "TABLE" | "CHART";
3232
type TimeframeId = "1Y" | "3Y" | "5Y" | "All";
33-
type Timeframe = {
33+
export type Timeframe = {
3434
id: TimeframeId;
3535
label: string;
3636
fromDate?: Date;
@@ -95,11 +95,12 @@ export default function NwHistoryPage() {
9595
},
9696
});
9797

98+
const timeframe = chartTimeframes.find(
99+
(timeframe) => timeframe.id === chartTimeframe,
100+
);
101+
98102
const chartData = useMemo(() => {
99103
const startingData = data.toReversed();
100-
const timeframe = chartTimeframes.find(
101-
(timeframe) => timeframe.id === chartTimeframe,
102-
);
103104
if (!timeframe?.fromDate) return startingData;
104105
const startIndex = findStartIndex(startingData, timeframe?.fromDate);
105106
return startingData.slice(startIndex);
@@ -162,7 +163,7 @@ export default function NwHistoryPage() {
162163
</TabsContent>
163164

164165
<TabsContent value={"CHART" satisfies Tab}>
165-
<Chart data={chartData} />
166+
<Chart data={chartData} selectedTimeframe={timeframe} />
166167
</TabsContent>
167168
</Tabs>
168169
</div>

0 commit comments

Comments
 (0)