diff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsx index 7cba4f177e..fea973690d 100644 --- a/packages/desktop-client/src/components/FinancesApp.tsx +++ b/packages/desktop-client/src/components/FinancesApp.tsx @@ -32,6 +32,7 @@ import { accountQueries } from '@desktop-client/accounts'; import { getLatestAppVersion, sync } from '@desktop-client/app/appSlice'; import { ProtectedRoute } from '@desktop-client/auth/ProtectedRoute'; import { Permissions } from '@desktop-client/auth/types'; +import { useAccounts } from '@desktop-client/hooks/useAccounts'; import { useGlobalPref } from '@desktop-client/hooks/useGlobalPref'; import { useLocalPref } from '@desktop-client/hooks/useLocalPref'; import { useMetaThemeColor } from '@desktop-client/hooks/useMetaThemeColor'; @@ -91,10 +92,7 @@ export function FinancesApp() { const dispatch = useDispatch(); const { t } = useTranslation(); - // TODO: Replace with `useAccounts` hook once it's updated to return the useQuery results. - const { data: accounts, isFetching: isAccountsFetching } = useQuery( - accountQueries.list(), - ); + const { data: accounts, isFetching: isAccountsFetching } = useAccounts(); const versionInfo = useSelector(state => state.app.versionInfo); const [notifyWhenUpdateIsAvailable] = useGlobalPref( diff --git a/packages/desktop-client/src/components/mobile/accounts/OffBudgetAccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/OffBudgetAccountTransactions.tsx index eede9d6ea6..95f2afee1f 100644 --- a/packages/desktop-client/src/components/mobile/accounts/OffBudgetAccountTransactions.tsx +++ b/packages/desktop-client/src/components/mobile/accounts/OffBudgetAccountTransactions.tsx @@ -49,7 +49,7 @@ function TransactionListWithPreviews() { } = useTransactions({ query: transactionsQuery, }); - const offBudgetAccounts = useOffBudgetAccounts(); + const { data: offBudgetAccounts = [] } = useOffBudgetAccounts(); const offBudgetAccountsFilter = useCallback( (schedule: ScheduleEntity) => offBudgetAccounts.some(a => a.id === schedule._account), diff --git a/packages/desktop-client/src/components/mobile/accounts/OnBudgetAccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/OnBudgetAccountTransactions.tsx index 9ec2cb4928..3c2fc2fa87 100644 --- a/packages/desktop-client/src/components/mobile/accounts/OnBudgetAccountTransactions.tsx +++ b/packages/desktop-client/src/components/mobile/accounts/OnBudgetAccountTransactions.tsx @@ -49,7 +49,7 @@ function TransactionListWithPreviews() { } = useTransactions({ query: transactionsQuery, }); - const onBudgetAccounts = useOnBudgetAccounts(); + const { data: onBudgetAccounts = [] } = useOnBudgetAccounts(); const onBudgetAccountsFilter = useCallback( (schedule: ScheduleEntity) => onBudgetAccounts.some(a => a.id === schedule._account), diff --git a/packages/desktop-client/src/components/sidebar/Accounts.tsx b/packages/desktop-client/src/components/sidebar/Accounts.tsx index 8bb0c1178a..87729a1d05 100644 --- a/packages/desktop-client/src/components/sidebar/Accounts.tsx +++ b/packages/desktop-client/src/components/sidebar/Accounts.tsx @@ -28,9 +28,9 @@ export function Accounts() { const { data: accounts = [] } = useAccounts(); const failedAccounts = useFailedAccounts(); const updatedAccounts = useUpdatedAccounts(); - const offbudgetAccounts = useOffBudgetAccounts(); - const onBudgetAccounts = useOnBudgetAccounts(); - const closedAccounts = useClosedAccounts(); + const { data: offbudgetAccounts = [] } = useOffBudgetAccounts(); + const { data: onBudgetAccounts = [] } = useOnBudgetAccounts(); + const { data: closedAccounts = [] } = useClosedAccounts(); const syncingAccountIds = useSelector(state => state.account.accountsSyncing); const getAccountPath = (account: AccountEntity) => `/accounts/${account.id}`; diff --git a/packages/desktop-client/src/hooks/useClosedAccounts.ts b/packages/desktop-client/src/hooks/useClosedAccounts.ts index 5d2cd3f283..051c933428 100644 --- a/packages/desktop-client/src/hooks/useClosedAccounts.ts +++ b/packages/desktop-client/src/hooks/useClosedAccounts.ts @@ -3,8 +3,5 @@ import { useQuery } from '@tanstack/react-query'; import { accountQueries } from '@desktop-client/accounts'; export function useClosedAccounts() { - const query = useQuery(accountQueries.listClosed()); - // TODO: Update to return query states (e.g. isFetching, isError, etc) - // so clients can handle loading and error states appropriately. - return query.data ?? []; + return useQuery(accountQueries.listClosed()); } diff --git a/packages/desktop-client/src/hooks/useOffBudgetAccounts.ts b/packages/desktop-client/src/hooks/useOffBudgetAccounts.ts index da0c939396..d6dde0bfaa 100644 --- a/packages/desktop-client/src/hooks/useOffBudgetAccounts.ts +++ b/packages/desktop-client/src/hooks/useOffBudgetAccounts.ts @@ -3,6 +3,5 @@ import { useQuery } from '@tanstack/react-query'; import { accountQueries } from '@desktop-client/accounts'; export function useOffBudgetAccounts() { - const query = useQuery(accountQueries.listOffBudget()); - return query.data ?? []; + return useQuery(accountQueries.listOffBudget()); } diff --git a/packages/desktop-client/src/hooks/useOnBudgetAccounts.ts b/packages/desktop-client/src/hooks/useOnBudgetAccounts.ts index edcae989cb..8e59e197cb 100644 --- a/packages/desktop-client/src/hooks/useOnBudgetAccounts.ts +++ b/packages/desktop-client/src/hooks/useOnBudgetAccounts.ts @@ -3,6 +3,5 @@ import { useQuery } from '@tanstack/react-query'; import { accountQueries } from '@desktop-client/accounts'; export function useOnBudgetAccounts() { - const query = useQuery(accountQueries.listOnBudget()); - return query.data ?? []; + return useQuery(accountQueries.listOnBudget()); } diff --git a/upcoming-release-notes/7071.md b/upcoming-release-notes/7071.md new file mode 100644 index 0000000000..58ff2991f3 --- /dev/null +++ b/upcoming-release-notes/7071.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [joel-jeremy] +--- + +Refactor account hooks to return full React Query states, enhancing data handling and component integration.