File tree Expand file tree Collapse file tree
src/app/dashboard/performance/net-worth-history Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import { APP_CURRENCY } from "~/constants";
2525import { calculateZeroInclusiveYAxisDomain } from "~/utils/chart" ;
2626import { formatDate } from "~/utils/date" ;
2727import { formatNumber } from "~/utils/number" ;
28+ import { Timeframe } from "./page" ;
2829
2930type 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
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import { isAfter, subYears } from "date-fns";
3030
3131type Tab = "TABLE" | "CHART" ;
3232type 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 >
You can’t perform that action at this time.
0 commit comments