From f025a7d9bf3fae619e50ae3d802c245be0e8da3f Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Thu, 7 May 2026 17:32:16 +0530 Subject: [PATCH] expand fixes --- src/components/LatestItems/LatestItems.tsx | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/components/LatestItems/LatestItems.tsx b/src/components/LatestItems/LatestItems.tsx index 9d0aef3..1439727 100644 --- a/src/components/LatestItems/LatestItems.tsx +++ b/src/components/LatestItems/LatestItems.tsx @@ -1,5 +1,3 @@ -// components/LatestItems/LatestItems.tsx - import * as React from "react"; import { List, @@ -12,7 +10,6 @@ import { IconButton } from "@mui/material"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; -import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import { ReportData, Transaction, ReportPeriod } from "../../features/report"; import { formatCurrency } from "../ProgressCard/ProgressCard.utils"; @@ -93,7 +90,6 @@ function extractTransactions( : (selected.incomes.transactions || []); } - // default → FULL periods = mergePeriods(reportData, "full"); if (!periods.length) return []; @@ -111,7 +107,7 @@ export default function LatestItems({ selectedPeriodId, accentColor }: Props) { - const [expanded, setExpanded] = React.useState(false); + const [visibleCount, setVisibleCount] = React.useState(5); const items = React.useMemo(() => { const txns = extractTransactions(reportData, selectedPeriodId, mode); @@ -136,22 +132,17 @@ export default function LatestItems({ const visibleItems = React.useMemo(() => { if (!isPeriodSelected) return items.slice(0, 5); - if (expanded) return items; - return items.slice(0, 5); - }, [items, isPeriodSelected, expanded]); + return items.slice(0, visibleCount); + }, [items, isPeriodSelected, visibleCount]); + + const canExpand = isPeriodSelected && visibleCount < items.length; return ( - + Recent Transactions - - {isPeriodSelected && items.length > 5 && ( - setExpanded((p) => !p)}> - {expanded ? : } - - )} @@ -202,6 +193,17 @@ export default function LatestItems({ ))} + + {canExpand && ( + + setVisibleCount((prev) => prev + 5)} + > + + + + )} );