A local-first personal finance app
fix(running-balance): resolve mobile toggle issue #6368 (#6379)
Tunde Jaiyesmic73b1afb74a2
diff --git a/packages/desktop-client/src/hooks/useTransactions.ts b/packages/desktop-client/src/hooks/useTransactions.tsindex 9b4b00fbd4..5d81764c8c 100644--- a/packages/desktop-client/src/hooks/useTransactions.ts+++ b/packages/desktop-client/src/hooks/useTransactions.ts@@ -14,7 +14,7 @@ type TransactionSplitsOption = 'all' | 'inline' | 'grouped' | 'none';type CalculateRunningBalancesOption =| ((- transactions: TransactionEntity[],+ transactions: readonly TransactionEntity[],splits: TransactionSplitsOption,startingBalance?: IntegerAmount,) => Map<TransactionEntity['id'], IntegerAmount>)@@ -173,6 +173,34 @@ export function useTransactions({};}, [query]);+ // Recalculate running balances whenever the transactions change or the+ // calculation options change (for example, when toggling show/hide+ // running balances). We intentionally keep the main data subscription+ // dependent only on `query` above, but this effect ensures running+ // balances are updated in-place when the caller changes options.+ useEffect(() => {+ const calculateFn = getCalculateRunningBalancesFn(+ options?.calculateRunningBalances,+ );++ if (calculateFn) {+ setRunningBalances(+ calculateFn(+ transactions,+ query?.state.tableOptions?.splits as TransactionSplitsOption,+ options?.startingBalance,+ ),+ );+ } else {+ setRunningBalances(new Map());+ }+ }, [+ transactions,+ query,+ options?.calculateRunningBalances,+ options?.startingBalance,+ ]);+const loadMore = useCallback(async () => {if (!pagedQueryRef.current) {return;diff --git a/upcoming-release-notes/6379.md b/upcoming-release-notes/6379.mdnew file mode 100644index 0000000000..12b4aa581d--- /dev/null+++ b/upcoming-release-notes/6379.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [Tundesjaiyesmi]+---++This PR address the bug of toggling running balance on mobile not updating the view immediately (required navigating to another screen and back).