From 9b2ff9df9b106de7a8c80b7e6ee6222077c21d59 Mon Sep 17 00:00:00 2001 From: Mikhail Verbitsky Date: Sat, 1 Aug 2026 00:00:26 +0200 Subject: [PATCH] fix: reset highlighted categories on year switch checked state in IncomeCard and NotFunCard was initialized once at mount, so switching years left stale selections: categories present in the new year but absent from the initial render stayed unhighlighted and were excluded from the totals. Reset the selection to all categories whenever the set of category ids changes. --- src/2-pages/Review/cards/IncomeCard/IncomeCard.tsx | 9 ++++++++- src/2-pages/Review/cards/NotFunCard/NotFunCard.tsx | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/2-pages/Review/cards/IncomeCard/IncomeCard.tsx b/src/2-pages/Review/cards/IncomeCard/IncomeCard.tsx index 0751e6162..39142b3c8 100644 --- a/src/2-pages/Review/cards/IncomeCard/IncomeCard.tsx +++ b/src/2-pages/Review/cards/IncomeCard/IncomeCard.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { Box, Typography, Chip, Stack } from '@mui/material' import { entries } from '6-shared/helpers/keys' import { addFxAmount } from '6-shared/helpers/money' @@ -35,6 +35,13 @@ export function IncomeCard(props: TCardProps) { const [checked, setChecked] = useState(incomeTags.map(t => t.id)) + const incomeIdsKey = incomeTags.map(t => t.id).join(',') + + useEffect(() => { + setChecked(incomeTags.map(t => t.id)) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [incomeIdsKey]) + const totalIncomeFx = incomeTags .filter(t => checked.includes(t.id)) .reduce((sum, t) => addFxAmount(sum, t.incomeFx), {}) diff --git a/src/2-pages/Review/cards/NotFunCard/NotFunCard.tsx b/src/2-pages/Review/cards/NotFunCard/NotFunCard.tsx index 629d3aa07..d48d37bae 100644 --- a/src/2-pages/Review/cards/NotFunCard/NotFunCard.tsx +++ b/src/2-pages/Review/cards/NotFunCard/NotFunCard.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useState } from 'react' +import React, { useEffect, useMemo, useState } from 'react' import { Box, Checkbox, @@ -38,6 +38,18 @@ export function NotFunCard(props: TCardProps) { const [checkedIncome, setCheckedIncome] = useState(income.map(t => t.id)) const [checkedOutcome, setCheckedOutcome] = useState(outcome.map(t => t.id)) + const incomeIdsKey = income.map(t => t.id).join(',') + const outcomeIdsKey = outcome.map(t => t.id).join(',') + + useEffect(() => { + setCheckedIncome(income.map(t => t.id)) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [incomeIdsKey]) + useEffect(() => { + setCheckedOutcome(outcome.map(t => t.id)) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [outcomeIdsKey]) + const [displayCurr] = displayCurrency.useDisplayCurrency() if (displayCurr !== 'RUB') return null