From 34594215f9efb47fa053e8f097738267c2b67eea Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Tue, 5 May 2026 12:58:59 +0530 Subject: [PATCH] using new state management --- .../HistoryChart/HistoryChart.models.ts | 18 +++++++++++-- src/components/HistoryChart/HistoryChart.tsx | 10 +++---- .../HistoryChart/HistoryChart.view.tsx | 26 +++++++++++-------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/components/HistoryChart/HistoryChart.models.ts b/src/components/HistoryChart/HistoryChart.models.ts index 88afa4c..014b405 100644 --- a/src/components/HistoryChart/HistoryChart.models.ts +++ b/src/components/HistoryChart/HistoryChart.models.ts @@ -1,3 +1,9 @@ +import { + DashboardMode, + DashboardPeriodType, + DashboardSelectedPeriodId +} from "../Dashboard"; + export interface _ChartDataPoint { id: string; amount: number; @@ -18,11 +24,19 @@ export interface HistoryChartProps { summary?: string; tabs: string[]; data: ChartData; - comparison: boolean; - setComparison: (v: boolean) => void; colorScheme: { primary: string; light: string; text: string; }; + + // State management + mode: DashboardMode; + periodType: DashboardPeriodType; + selectedPeriodId: DashboardSelectedPeriodId; + comparison: boolean; + + togglePeriodType: () => void; + setSelectedPeriodId: (id: string | null) => void; + toggleComparison: () => void; } diff --git a/src/components/HistoryChart/HistoryChart.tsx b/src/components/HistoryChart/HistoryChart.tsx index 53c5ed1..c890da0 100644 --- a/src/components/HistoryChart/HistoryChart.tsx +++ b/src/components/HistoryChart/HistoryChart.tsx @@ -3,7 +3,7 @@ import { ChartDataPoint, HistoryChartProps, ChartData } from "./HistoryChart.mod import HistoryChartView from "./HistoryChart.view"; export default function HistoryChart(props: HistoryChartProps) { - const { tabs, data, periodType, comparison } = props; + const { tabs, data, mode, periodType, comparison } = props; const [activeTab, setActiveTab] = React.useState(tabs[0] || ""); const [startIndex, setStartIndex] = React.useState(0); @@ -12,12 +12,8 @@ export default function HistoryChart(props: HistoryChartProps) { let rawData: ChartDataPoint[] = []; - if (activeDataKey === "daily") { - rawData = data.daily || []; - } else { - const section = data[activeDataKey]; - rawData = section?.[periodType] || []; - } + const section = data[activeDataKey]; + rawData = section?.[periodType] || []; const currentData = rawData; diff --git a/src/components/HistoryChart/HistoryChart.view.tsx b/src/components/HistoryChart/HistoryChart.view.tsx index 15cf0bc..13a4cf2 100644 --- a/src/components/HistoryChart/HistoryChart.view.tsx +++ b/src/components/HistoryChart/HistoryChart.view.tsx @@ -26,8 +26,6 @@ interface ViewProps extends HistoryChartProps { startIndex: number; setStartIndex: React.Dispatch>; activeDataKey: string; - selectedPeriodId: string | null; - onSelectPeriodId: (id: string | null) => void; } export default function HistoryChartView(props: ViewProps) { @@ -35,11 +33,19 @@ export default function HistoryChartView(props: ViewProps) { header, summary, tabs, - periodType, - onPeriodTypeChange, - comparison, - setComparison, colorScheme, + + // State management + mode, + periodType, + selectedPeriodId, + comparison, + + togglePeriodType, + setSelectedPeriodId, + toggleComparison, + + // HistoryChart state management activeTab, setActiveTab, currentData, @@ -49,8 +55,6 @@ export default function HistoryChartView(props: ViewProps) { startIndex, setStartIndex, activeDataKey, - selectedPeriodId, - onSelectPeriodId, } = props; const theme = useTheme(); @@ -103,7 +107,7 @@ export default function HistoryChartView(props: ViewProps) { - v && onPeriodTypeChange(v)} size="small"> + Rolling Calendar @@ -113,7 +117,7 @@ export default function HistoryChartView(props: ViewProps) { setComparison(!comparison)} + onChange={toggleComparison} size="small" sx={{ textTransform: "none", @@ -169,7 +173,7 @@ export default function HistoryChartView(props: ViewProps) { return ( onSelectPeriodId(isSelected ? null : point.id)} + onClick={() => setSelectedPeriodId(isSelected ? null : point.id)} sx={{ flex: 1, display: "flex",