From 7b0b3fb6155ff4148219c2956b4c1cf4a77c717d Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Fri, 1 May 2026 17:40:54 +0530 Subject: [PATCH] period selection --- src/Dashboard.tsx | 3 +++ src/components/Dashboard/Dashboard.models.ts | 2 ++ src/components/Dashboard/Dashboard.view.tsx | 6 ++++- .../HistoryChart/HistoryChart.view.tsx | 22 +++++++++++++++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Dashboard.tsx b/src/Dashboard.tsx index a045492..baa9522 100644 --- a/src/Dashboard.tsx +++ b/src/Dashboard.tsx @@ -12,6 +12,7 @@ import { useDashboardData } from "./features/dashboard"; export default function Dashboard() { const [mode, setMode] = React.useState<"expense" | "income">("expense"); + const [selectedPeriodId, setSelectedPeriodId] = React.useState(null); const { data, latest, isLoading, error } = useDashboardData(mode); if (isLoading) { @@ -40,6 +41,8 @@ export default function Dashboard() { data={data} latest={latest} onModeChange={(newMode) => setMode(newMode)} + selectedPeriodId={selectedPeriodId} + onSelectPeriodId={(newPeriodId) => setSelectedPeriodId(newPeriodId)} /> ); } diff --git a/src/components/Dashboard/Dashboard.models.ts b/src/components/Dashboard/Dashboard.models.ts index 0e16827..d653383 100644 --- a/src/components/Dashboard/Dashboard.models.ts +++ b/src/components/Dashboard/Dashboard.models.ts @@ -46,4 +46,6 @@ export interface DashboardProps { data: any; // Aggregated data from features latest: any[]; // Latest items from features onModeChange?: (mode: DashboardMode) => void; + selectedPeriodId: string | null; + onSelectPeriodId: (id: string | null) => void; } diff --git a/src/components/Dashboard/Dashboard.view.tsx b/src/components/Dashboard/Dashboard.view.tsx index 01f254f..6019d93 100644 --- a/src/components/Dashboard/Dashboard.view.tsx +++ b/src/components/Dashboard/Dashboard.view.tsx @@ -21,7 +21,9 @@ export default function DashboardView({ latest, state, setState, - onModeChange + onModeChange, + selectedPeriodId, + onSelectPeriodId, }: ViewProps) { const theme = useTheme(); const themeMode = theme.palette.mode; @@ -143,6 +145,8 @@ export default function DashboardView({ onPeriodTypeChange={(p: any) => setState(prev => ({ ...prev, periodType: p }))} comparison={comparison} setComparison={(c: any) => setState(prev => ({ ...prev, comparison: c }))} + selectedPeriodId={selectedPeriodId} + onSelectPeriodId={onSelectPeriodId} /> )} diff --git a/src/components/HistoryChart/HistoryChart.view.tsx b/src/components/HistoryChart/HistoryChart.view.tsx index 80e0b9b..15cf0bc 100644 --- a/src/components/HistoryChart/HistoryChart.view.tsx +++ b/src/components/HistoryChart/HistoryChart.view.tsx @@ -26,6 +26,8 @@ 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) { @@ -47,6 +49,8 @@ export default function HistoryChartView(props: ViewProps) { startIndex, setStartIndex, activeDataKey, + selectedPeriodId, + onSelectPeriodId, } = props; const theme = useTheme(); @@ -159,9 +163,23 @@ export default function HistoryChartView(props: ViewProps) { ? ((point.compare?.amount ?? 0) / maxAmount) * 100 : 0; const labelHeight = Math.max(currentHeight, compareHeight); + const isSelected = selectedPeriodId === point.id; + const display = formatDisplay(point, activeTab.toLowerCase(), comparison); return ( - + onSelectPeriodId(isSelected ? null : point.id)} + sx={{ + flex: 1, + display: "flex", + flexDirection: "column", + alignItems: "center", + justifyContent: "flex-end", + height: "100%", + cursor: "pointer" + }} + > - {formatDisplay(point, activeTab.toLowerCase(), comparison)} + {isSelected ? `SELECTED: ${display}` : display} {comparison && (