diff --git a/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx b/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx index 08a4d7cba7..2f3c6a5592 100644 --- a/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx +++ b/packages/desktop-client/src/components/mobile/schedules/MobileSchedulesPage.tsx @@ -23,10 +23,8 @@ import { useDateFormat } from '@desktop-client/hooks/useDateFormat'; import { useFormat } from '@desktop-client/hooks/useFormat'; import { useNavigate } from '@desktop-client/hooks/useNavigate'; import { usePayees } from '@desktop-client/hooks/usePayees'; -import { - useSchedules, - useScheduleStatus, -} from '@desktop-client/hooks/useSchedules'; +import { useSchedules } from '@desktop-client/hooks/useSchedules'; +import { useScheduleStatus } from '@desktop-client/hooks/useScheduleStatus'; import { useUndo } from '@desktop-client/hooks/useUndo'; import { addNotification } from '@desktop-client/notifications/notificationsSlice'; import { useDispatch } from '@desktop-client/redux'; diff --git a/packages/desktop-client/src/components/rules/RuleEditor.tsx b/packages/desktop-client/src/components/rules/RuleEditor.tsx index ae5e18c825..d23b5922b3 100644 --- a/packages/desktop-client/src/components/rules/RuleEditor.tsx +++ b/packages/desktop-client/src/components/rules/RuleEditor.tsx @@ -58,10 +58,8 @@ import { GenericInput } from '@desktop-client/components/util/GenericInput'; import { useDateFormat } from '@desktop-client/hooks/useDateFormat'; import { useFeatureFlag } from '@desktop-client/hooks/useFeatureFlag'; import { useFormat } from '@desktop-client/hooks/useFormat'; -import { - useSchedules, - useScheduleStatus, -} from '@desktop-client/hooks/useSchedules'; +import { useSchedules } from '@desktop-client/hooks/useSchedules'; +import { useScheduleStatus } from '@desktop-client/hooks/useScheduleStatus'; import { SelectedProvider, useSelected, diff --git a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx index 3c0b229536..23f9ac17ac 100644 --- a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx +++ b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx @@ -20,10 +20,8 @@ import { ModalHeader, } from '@desktop-client/components/common/Modal'; import { Search } from '@desktop-client/components/common/Search'; -import { - useSchedules, - useScheduleStatus, -} from '@desktop-client/hooks/useSchedules'; +import { useSchedules } from '@desktop-client/hooks/useSchedules'; +import { useScheduleStatus } from '@desktop-client/hooks/useScheduleStatus'; import { pushModal } from '@desktop-client/modals/modalsSlice'; import type { Modal as ModalType } from '@desktop-client/modals/modalsSlice'; import { useDispatch } from '@desktop-client/redux'; diff --git a/packages/desktop-client/src/components/schedules/index.tsx b/packages/desktop-client/src/components/schedules/index.tsx index 1b982f27ac..8aad4adb4c 100644 --- a/packages/desktop-client/src/components/schedules/index.tsx +++ b/packages/desktop-client/src/components/schedules/index.tsx @@ -14,10 +14,8 @@ import type { ScheduleItemAction } from './SchedulesTable'; import { Search } from '@desktop-client/components/common/Search'; import { Page } from '@desktop-client/components/Page'; -import { - useSchedules, - useScheduleStatus, -} from '@desktop-client/hooks/useSchedules'; +import { useSchedules } from '@desktop-client/hooks/useSchedules'; +import { useScheduleStatus } from '@desktop-client/hooks/useScheduleStatus'; import { pushModal } from '@desktop-client/modals/modalsSlice'; import { useDispatch } from '@desktop-client/redux'; diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts index c3dd3ecd80..a9956f1a01 100644 --- a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts +++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts @@ -4,7 +4,7 @@ import type { CategoryEntity, ScheduleEntity } from 'loot-core/types/models'; import { useCachedSchedules } from './useCachedSchedules'; import { useFeatureFlag } from './useFeatureFlag'; -import { useScheduleStatus } from './useSchedules'; +import { useScheduleStatus } from './useScheduleStatus'; import type { ScheduleStatusData } from '@desktop-client/schedules'; diff --git a/packages/desktop-client/src/hooks/usePreviewTransactions.ts b/packages/desktop-client/src/hooks/usePreviewTransactions.ts index 4a55323da4..97d438aa0e 100644 --- a/packages/desktop-client/src/hooks/usePreviewTransactions.ts +++ b/packages/desktop-client/src/hooks/usePreviewTransactions.ts @@ -7,7 +7,7 @@ import type { IntegerAmount } from 'loot-core/shared/util'; import type { ScheduleEntity, TransactionEntity } from 'loot-core/types/models'; import { useCachedSchedules } from './useCachedSchedules'; -import { useScheduleStatus } from './useSchedules'; +import { useScheduleStatus } from './useScheduleStatus'; import { useSyncedPref } from './useSyncedPref'; import { calculateRunningBalancesBottomUp } from './useTransactions'; diff --git a/packages/desktop-client/src/hooks/useScheduleStatus.ts b/packages/desktop-client/src/hooks/useScheduleStatus.ts new file mode 100644 index 0000000000..82692b7045 --- /dev/null +++ b/packages/desktop-client/src/hooks/useScheduleStatus.ts @@ -0,0 +1,29 @@ +import { useQuery } from '@tanstack/react-query'; +import type { UseQueryResult } from '@tanstack/react-query'; + +import type { ScheduleEntity } from 'loot-core/types/models'; + +import { useSyncedPref } from './useSyncedPref'; + +import { scheduleQueries } from '@desktop-client/schedules'; +import type { ScheduleStatusData } from '@desktop-client/schedules'; + +type UseScheduleStatusProps = { + schedules: ScheduleEntity[]; +}; + +type UseScheduleStatusResult = UseQueryResult; + +export function useScheduleStatus({ + schedules, +}: UseScheduleStatusProps): UseScheduleStatusResult { + const [upcomingLength = '7'] = useSyncedPref( + 'upcomingScheduledTransactionLength', + ); + return useQuery( + scheduleQueries.statuses({ + schedules, + upcomingLength, + }), + ); +} diff --git a/packages/desktop-client/src/hooks/useSchedules.ts b/packages/desktop-client/src/hooks/useSchedules.ts index 38bfe67b48..96bd5c86a0 100644 --- a/packages/desktop-client/src/hooks/useSchedules.ts +++ b/packages/desktop-client/src/hooks/useSchedules.ts @@ -4,10 +4,7 @@ import type { UseQueryResult } from '@tanstack/react-query'; import type { Query } from 'loot-core/shared/query'; import type { ScheduleEntity } from 'loot-core/types/models'; -import { useSyncedPref } from './useSyncedPref'; - import { scheduleQueries } from '@desktop-client/schedules'; -import type { ScheduleStatusData } from '@desktop-client/schedules'; export type UseSchedulesProps = { query?: Query; @@ -19,21 +16,3 @@ export function useSchedules({ }: UseSchedulesProps = {}): UseSchedulesResult { return useQuery(scheduleQueries.aql({ query })); } - -type UseScheduleStatusProps = { - schedules: ScheduleEntity[]; -}; - -type UseScheduleStatusResult = UseQueryResult; - -export function useScheduleStatus({ - schedules, -}: UseScheduleStatusProps): UseScheduleStatusResult { - const [upcomingLength = '7'] = useSyncedPref('upcomingScheduledTransactionLength'); - return useQuery( - scheduleQueries.statuses({ - schedules, - upcomingLength, - }), - ); -}