Skip to content

A local-first personal finance app

Move loot-core/client/data-hooks over to desktop-client package (#4828)

Joel Jeremy Marquezfdf213865df7
diff --git a/packages/desktop-client/src/components/ManageRules.tsx b/packages/desktop-client/src/components/ManageRules.tsx
index b532411936..166b38a181 100644
--- a/packages/desktop-client/src/components/ManageRules.tsx
+++ b/packages/desktop-client/src/components/ManageRules.tsx
@@ -15,7 +15,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { send } from 'loot-core/platform/client/fetch';
import * as undo from 'loot-core/platform/client/undo';
import { getNormalisedString } from 'loot-core/shared/normalisation';
@@ -37,6 +36,7 @@ import { RulesList } from './rules/RulesList';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
import {
useSelected,
SelectedProvider,
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index 7ec73d210e..e20f6d9808 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -16,11 +16,6 @@ import { debounce } from 'debounce';
import { t } from 'i18next';
import { v4 as uuidv4 } from 'uuid';
-import { useFilters } from 'loot-core/client/data-hooks/filters';
-import {
- SchedulesProvider,
- accountSchedulesQuery,
-} from 'loot-core/client/data-hooks/schedules';
import * as queries from 'loot-core/client/queries';
import {
aqlQuery,
@@ -77,11 +72,13 @@ import { AccountHeader } from './Header';
import { useAccountPreviewTransactions } from '@desktop-client/hooks/useAccountPreviewTransactions';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useFailedAccounts } from '@desktop-client/hooks/useFailedAccounts';
import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import { accountSchedulesQuery } from '@desktop-client/hooks/useSchedules';
import {
SelectedProviderWithItems,
type Actions,
@@ -92,6 +89,7 @@ import {
} from '@desktop-client/hooks/useSplitsExpanded';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
import { useTransactionBatchActions } from '@desktop-client/hooks/useTransactionBatchActions';
+import { useTransactionFilters } from '@desktop-client/hooks/useTransactionFilters';
type ConditionEntity = Partial<RuleConditionEntity> | TransactionFilterEntity;
@@ -1948,7 +1946,7 @@ export function Account() {
const accountsSyncing = useSelector(state => state.account.accountsSyncing);
const filterConditions = location?.state?.filterConditions || [];
- const savedFiters = useFilters();
+ const savedFiters = useTransactionFilters();
const schedulesQuery = useMemo(
() => accountSchedulesQuery(params.id),
diff --git a/packages/desktop-client/src/components/accounts/Balance.tsx b/packages/desktop-client/src/components/accounts/Balance.tsx
index ef78e18d09..ab3b8eaf3a 100644
--- a/packages/desktop-client/src/components/accounts/Balance.tsx
+++ b/packages/desktop-client/src/components/accounts/Balance.tsx
@@ -8,7 +8,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { useHover } from 'usehooks-ts';
-import { useCachedSchedules } from 'loot-core/client/data-hooks/schedules';
import { q, type Query } from 'loot-core/shared/query';
import { getScheduledAmount } from 'loot-core/shared/schedules';
import { isPreviewId } from 'loot-core/shared/transactions';
@@ -20,6 +19,7 @@ import { CellValue, CellValueText } from '../spreadsheet/CellValue';
import { useFormat } from '../spreadsheet/useFormat';
import { useSheetValue } from '../spreadsheet/useSheetValue';
+import { useCachedSchedules } from '@desktop-client/hooks/useCachedSchedules';
import { useSelectedItems } from '@desktop-client/hooks/useSelected';
type DetailedBalanceProps = {
diff --git a/packages/desktop-client/src/components/autocomplete/FilterAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/FilterAutocomplete.tsx
index 653051122a..4ad20926e8 100644
--- a/packages/desktop-client/src/components/autocomplete/FilterAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/FilterAutocomplete.tsx
@@ -1,8 +1,9 @@
import React, { type ComponentProps } from 'react';
-import { useFilters } from 'loot-core/client/data-hooks/filters';
import { type TransactionFilterEntity } from 'loot-core/types/models';
+import { useTransactionFilters } from '../../hooks/useTransactionFilters';
+
import { Autocomplete } from './Autocomplete';
import { FilterList } from './FilterList';
@@ -12,7 +13,7 @@ export function FilterAutocomplete({
}: {
embedded?: boolean;
} & ComponentProps<typeof Autocomplete<TransactionFilterEntity>>) {
- const filters = useFilters() || [];
+ const filters = useTransactionFilters() || [];
return (
<Autocomplete
diff --git a/packages/desktop-client/src/components/autocomplete/ReportAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/ReportAutocomplete.tsx
index 397af5e608..bc6fb9896b 100644
--- a/packages/desktop-client/src/components/autocomplete/ReportAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/ReportAutocomplete.tsx
@@ -1,8 +1,9 @@
import React, { type ComponentProps } from 'react';
-import { useReports } from 'loot-core/client/data-hooks/reports';
import { type CustomReportEntity } from 'loot-core/types/models';
+import { useReports } from '../../hooks/useReports';
+
import { Autocomplete } from './Autocomplete';
import { ReportList } from './ReportList';
diff --git a/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx b/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx
index a3af08e51b..7599140b32 100644
--- a/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx
+++ b/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx
@@ -9,7 +9,6 @@ import { theme } from '@actual-app/components/theme';
import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';
-import { useTransactions } from 'loot-core/client/data-hooks/transactions';
import {
defaultMappings,
type Mappings,
@@ -31,6 +30,7 @@ import { CheckboxOption } from '../modals/ImportTransactionsModal/CheckboxOption
import { FieldMapping } from './FieldMapping';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
+import { useTransactions } from '@desktop-client/hooks/useTransactions';
export type TransactionDirection = 'payment' | 'deposit';
diff --git a/packages/desktop-client/src/components/budget/BudgetTable.tsx b/packages/desktop-client/src/components/budget/BudgetTable.tsx
index 46c13acdc8..d26c8e96ea 100644
--- a/packages/desktop-client/src/components/budget/BudgetTable.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetTable.tsx
@@ -9,7 +9,6 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
import { q } from 'loot-core/shared/query';
import {
type CategoryEntity,
@@ -29,6 +28,7 @@ import {
separateGroups,
} from './util';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useGlobalPref } from '@desktop-client/hooks/useGlobalPref';
import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
diff --git a/packages/desktop-client/src/components/filters/FiltersMenu.jsx b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
index b591053f8b..e204842f7b 100644
--- a/packages/desktop-client/src/components/filters/FiltersMenu.jsx
+++ b/packages/desktop-client/src/components/filters/FiltersMenu.jsx
@@ -20,7 +20,6 @@ import {
isValid as isDateValid,
} from 'date-fns';
-import { useFilters } from 'loot-core/client/data-hooks/filters';
import { send } from 'loot-core/platform/client/fetch';
import { getMonthYearFormat } from 'loot-core/shared/months';
import {
@@ -43,6 +42,7 @@ import { subfieldToOptions } from './subfieldToOptions';
import { updateFilterReducer } from './updateFilterReducer';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { useTransactionFilters } from '@desktop-client/hooks/useTransactionFilters';
let isDatepickerClick = false;
@@ -260,7 +260,7 @@ function ConfigureField({
export function FilterButton({ onApply, compact, hover, exclude }) {
const { t } = useTranslation();
- const filters = useFilters();
+ const filters = useTransactionFilters();
const triggerRef = useRef(null);
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
index ce433f1bd6..1ceddfb0df 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx
@@ -13,14 +13,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import {
- accountSchedulesQuery,
- SchedulesProvider,
-} from 'loot-core/client/data-hooks/schedules';
-import {
- useTransactions,
- useTransactionsSearch,
-} from 'loot-core/client/data-hooks/transactions';
import * as queries from 'loot-core/client/queries';
import { listen, send } from 'loot-core/platform/client/fetch';
import { type Query } from 'loot-core/shared/query';
@@ -48,9 +40,13 @@ import { AddTransactionButton } from '../transactions/AddTransactionButton';
import { TransactionListWithBalances } from '../transactions/TransactionListWithBalances';
import { useAccountPreviewTransactions } from '@desktop-client/hooks/useAccountPreviewTransactions';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useFailedAccounts } from '@desktop-client/hooks/useFailedAccounts';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { accountSchedulesQuery } from '@desktop-client/hooks/useSchedules';
+import { useTransactions } from '@desktop-client/hooks/useTransactions';
+import { useTransactionsSearch } from '@desktop-client/hooks/useTransactionsSearch';
export function AccountTransactions({
account,
diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
index 32c85eae57..32ef05b89e 100644
--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
@@ -23,7 +23,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { AutoTextSize } from 'auto-text-size';
-import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
import {
envelopeBudget,
trackingBudget,
@@ -46,6 +45,7 @@ import { PullToRefresh } from '../PullToRefresh';
import { ExpenseGroupList } from './ExpenseGroupList';
import { IncomeGroup } from './IncomeGroup';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
index 3f9bd83a33..c0767dec63 100644
--- a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
@@ -3,11 +3,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { TextOneLine } from '@actual-app/components/text-one-line';
import { View } from '@actual-app/components/view';
-import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
-import {
- useTransactions,
- useTransactionsSearch,
-} from 'loot-core/client/data-hooks/transactions';
import * as queries from 'loot-core/client/queries';
import { listen } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
@@ -24,10 +19,13 @@ import { MobileBackButton } from '../MobileBackButton';
import { AddTransactionButton } from '../transactions/AddTransactionButton';
import { TransactionListWithBalances } from '../transactions/TransactionListWithBalances';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategoryPreviewTransactions } from '@desktop-client/hooks/useCategoryPreviewTransactions';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useTransactions } from '@desktop-client/hooks/useTransactions';
+import { useTransactionsSearch } from '@desktop-client/hooks/useTransactionsSearch';
type CategoryTransactionsProps = {
category: CategoryEntity;
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
index c3490219b3..b49698bffc 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
@@ -29,7 +29,6 @@ import {
useLongPress,
} from '@react-aria/interactions';
-import { useCachedSchedules } from 'loot-core/client/data-hooks/schedules';
import { isPreviewId } from 'loot-core/shared/transactions';
import { integerToCurrency } from 'loot-core/shared/util';
import {
@@ -43,6 +42,7 @@ import { makeAmountFullStyle } from '../../budget/util';
import { lookupName, Status } from './TransactionEdit';
import { useAccount } from '@desktop-client/hooks/useAccount';
+import { useCachedSchedules } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDisplayPayee } from '@desktop-client/hooks/useDisplayPayee';
import { usePayee } from '@desktop-client/hooks/usePayee';
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
index b86cb3ae89..c88e5bb670 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal.tsx
@@ -6,7 +6,6 @@ import { Stack } from '@actual-app/components/stack';
import { theme } from '@actual-app/components/theme';
import { uniqueId } from 'lodash';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { type Template } from 'loot-core/server/budget/types/templates';
import { q } from 'loot-core/shared/query';
@@ -14,6 +13,8 @@ import { BudgetAutomation } from '../budget/goals/BudgetAutomation';
import { useBudgetAutomationCategories } from '../budget/goals/useBudgetAutomationCategories';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
+
type TemplateWithId = Template & { id: string };
export function BudgetAutomationsModal() {
diff --git a/packages/desktop-client/src/components/modals/EditRuleModal.jsx b/packages/desktop-client/src/components/modals/EditRuleModal.jsx
index 3e86a30516..4f4b82a76a 100644
--- a/packages/desktop-client/src/components/modals/EditRuleModal.jsx
+++ b/packages/desktop-client/src/components/modals/EditRuleModal.jsx
@@ -23,7 +23,6 @@ import { View } from '@actual-app/components/view';
import { css } from '@emotion/css';
import { v4 as uuid } from 'uuid';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { aqlQuery } from 'loot-core/client/query-helpers';
import { enableUndo, disableUndo } from 'loot-core/client/undo';
import { send } from 'loot-core/platform/client/fetch';
@@ -58,6 +57,7 @@ import { GenericInput } from '../util/GenericInput';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useFeatureFlag } from '@desktop-client/hooks/useFeatureFlag';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
import {
useSelected,
SelectedProvider,
diff --git a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
index 7b63599e2b..4fd9d65f30 100644
--- a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx
@@ -11,7 +11,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { format } from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
import {
@@ -28,6 +27,7 @@ import {
} from '../common/Modal';
import { useLocale } from '@desktop-client/hooks/useLocale';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
type ScheduledTransactionMenuModalProps = Extract<
ModalType,
diff --git a/packages/desktop-client/src/components/reports/Overview.tsx b/packages/desktop-client/src/components/reports/Overview.tsx
index 410c7ccf9a..52d189fbc6 100644
--- a/packages/desktop-client/src/components/reports/Overview.tsx
+++ b/packages/desktop-client/src/components/reports/Overview.tsx
@@ -13,8 +13,6 @@ import { Popover } from '@actual-app/components/popover';
import { breakpoints } from '@actual-app/components/tokens';
import { View } from '@actual-app/components/view';
-import { useDashboard } from 'loot-core/client/data-hooks/dashboard';
-import { useReports } from 'loot-core/client/data-hooks/reports';
import { send } from 'loot-core/platform/client/fetch';
import {
type CustomReportWidget,
@@ -43,7 +41,9 @@ import './overview.scss';
import { SummaryCard } from './reports/SummaryCard';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
+import { useDashboard } from '@desktop-client/hooks/useDashboard';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useReports } from '@desktop-client/hooks/useReports';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
import { useUndo } from '@desktop-client/hooks/useUndo';
diff --git a/packages/desktop-client/src/components/reports/SaveReport.tsx b/packages/desktop-client/src/components/reports/SaveReport.tsx
index 5fe41af798..2b9b41f2dc 100644
--- a/packages/desktop-client/src/components/reports/SaveReport.tsx
+++ b/packages/desktop-client/src/components/reports/SaveReport.tsx
@@ -6,10 +6,11 @@ import { Popover } from '@actual-app/components/popover';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
-import { useReports } from 'loot-core/client/data-hooks/reports';
import { send, sendCatch } from 'loot-core/platform/client/fetch';
import { type CustomReportEntity } from 'loot-core/types/models';
+import { useReports } from '../../hooks/useReports';
+
import { SaveReportChoose } from './SaveReportChoose';
import { SaveReportDelete } from './SaveReportDelete';
import { SaveReportMenu } from './SaveReportMenu';
diff --git a/packages/desktop-client/src/components/reports/reports/Calendar.tsx b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
index dcae987e79..8cdc852a1d 100644
--- a/packages/desktop-client/src/components/reports/reports/Calendar.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Calendar.tsx
@@ -25,9 +25,6 @@ import { css } from '@emotion/css';
import { useDrag } from '@use-gesture/react';
import { format, parseISO } from 'date-fns';
-import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
-import { useTransactions } from 'loot-core/client/data-hooks/transactions';
-import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q, type Query } from 'loot-core/shared/query';
@@ -63,17 +60,20 @@ import { useReport } from '../useReport';
import { fromDateRepr } from '../util';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePayees } from '@desktop-client/hooks/usePayees';
import { useResizeObserver } from '@desktop-client/hooks/useResizeObserver';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
import { SelectedProviderWithItems } from '@desktop-client/hooks/useSelected';
import { SplitsExpandedProvider } from '@desktop-client/hooks/useSplitsExpanded';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
+import { useTransactions } from '@desktop-client/hooks/useTransactions';
+import { useWidget } from '@desktop-client/hooks/useWidget';
const CHEVRON_HEIGHT = 42;
const SUMMARY_HEIGHT = 140;
@@ -136,7 +136,10 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters(widget?.meta?.conditions, widget?.meta?.conditionsOp);
+ } = useRuleConditionFilters(
+ widget?.meta?.conditions,
+ widget?.meta?.conditionsOp,
+ );
useEffect(() => {
const day = parameters.get('day');
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
index 657dd252df..db1edc0b97 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
@@ -12,7 +12,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import * as d from 'date-fns';
-import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { integerToCurrency } from 'loot-core/shared/util';
@@ -36,10 +35,11 @@ import { calculateTimeRange } from '../reportRanges';
import { cashFlowByDate } from '../spreadsheets/cash-flow-spreadsheet';
import { useReport } from '../useReport';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
+import { useWidget } from '@desktop-client/hooks/useWidget';
export const defaultTimeFrame = {
start: monthUtils.dayFromDate(monthUtils.currentMonth()),
@@ -77,7 +77,7 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters<RuleConditionEntity>(
+ } = useRuleConditionFilters<RuleConditionEntity>(
widget?.meta?.conditions,
widget?.meta?.conditionsOp,
);
diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
index f097ca9302..6dc44332ab 100644
--- a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
@@ -11,7 +11,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import * as d from 'date-fns';
-import { useReport as useCustomReport } from 'loot-core/client/data-hooks/reports';
import { calculateHasWarning } from 'loot-core/client/reports';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
@@ -58,11 +57,12 @@ import { fromDateRepr } from '../util';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import { useReport as useCustomReport } from '@desktop-client/hooks/useReport';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
/**
@@ -145,7 +145,7 @@ function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters();
+ } = useRuleConditionFilters();
const location = useLocation();
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
index e4233f1611..fa5f009c7b 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
@@ -10,7 +10,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import * as d from 'date-fns';
-import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { integerToCurrency } from 'loot-core/shared/util';
@@ -32,10 +31,11 @@ import { useReport } from '../useReport';
import { fromDateRepr } from '../util';
import { useAccounts } from '@desktop-client/hooks/useAccounts';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
+import { useWidget } from '@desktop-client/hooks/useWidget';
export function NetWorth() {
const params = useParams();
@@ -68,7 +68,10 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters(widget?.meta?.conditions, widget?.meta?.conditionsOp);
+ } = useRuleConditionFilters(
+ widget?.meta?.conditions,
+ widget?.meta?.conditionsOp,
+ );
const [allMonths, setAllMonths] = useState<Array<{
name: string;
diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsx
index 2796492369..3b65e6b133 100644
--- a/packages/desktop-client/src/components/reports/reports/Spending.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx
@@ -16,7 +16,6 @@ import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';
import * as d from 'date-fns';
-import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { amountToCurrency } from 'loot-core/shared/util';
@@ -42,9 +41,10 @@ import { createSpendingSpreadsheet } from '../spreadsheets/spending-spreadsheet'
import { useReport } from '../useReport';
import { fromDateRepr } from '../util';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
+import { useWidget } from '@desktop-client/hooks/useWidget';
export function Spending() {
const params = useParams();
@@ -76,7 +76,7 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters<RuleConditionEntity>(
+ } = useRuleConditionFilters<RuleConditionEntity>(
widget?.meta?.conditions,
widget?.meta?.conditionsOp,
);
diff --git a/packages/desktop-client/src/components/reports/reports/Summary.tsx b/packages/desktop-client/src/components/reports/reports/Summary.tsx
index ec3101da29..ad32de33c0 100644
--- a/packages/desktop-client/src/components/reports/reports/Summary.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Summary.tsx
@@ -15,7 +15,6 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { parseISO } from 'date-fns';
-import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { amountToCurrency } from 'loot-core/shared/util';
@@ -43,10 +42,11 @@ import { summarySpreadsheet } from '../spreadsheets/summary-spreadsheet';
import { useReport } from '../useReport';
import { fromDateRepr } from '../util';
-import { useFilters } from '@desktop-client/hooks/useFilters';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { useRuleConditionFilters } from '@desktop-client/hooks/useRuleConditionFilters';
import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
+import { useWidget } from '@desktop-client/hooks/useWidget';
export function Summary() {
const params = useParams();
@@ -66,7 +66,7 @@ type SummaryInnerProps = {
widget?: SummaryWidget;
};
-type FilterObject = ReturnType<typeof useFilters>;
+type FilterObject = ReturnType<typeof useRuleConditionFilters>;
function SummaryInner({ widget }: SummaryInnerProps) {
const locale = useLocale();
@@ -83,7 +83,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
const [end, setEnd] = useState(initialEnd);
const [mode, setMode] = useState(initialMode);
- const dividendFilters: FilterObject = useFilters(
+ const dividendFilters: FilterObject = useRuleConditionFilters(
widget?.meta?.conditions ?? [],
widget?.meta?.conditionsOp ?? 'and',
);
@@ -111,7 +111,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
},
);
- const divisorFilters = useFilters(
+ const divisorFilters = useRuleConditionFilters(
content.type === 'percentage' ? (content?.divisorConditions ?? []) : [],
content.type === 'percentage'
? (content?.divisorConditionsOp ?? 'and')
diff --git a/packages/desktop-client/src/components/rules/ScheduleValue.tsx b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
index b8e5ed5677..e465273ed3 100644
--- a/packages/desktop-client/src/components/rules/ScheduleValue.tsx
+++ b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
@@ -3,7 +3,6 @@ import React, { useMemo } from 'react';
import { AnimatedLoading } from '@actual-app/components/icons/AnimatedLoading';
import { View } from '@actual-app/components/view';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { q } from 'loot-core/shared/query';
import { describeSchedule } from 'loot-core/shared/schedules';
import { type ScheduleEntity } from 'loot-core/types/models';
@@ -13,6 +12,7 @@ import { getPayeesById } from '../../queries/queriesSlice';
import { Value } from './Value';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
type ScheduleValueProps = {
value: ScheduleEntity;
diff --git a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
index 8ac67661df..ed784cb465 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx
@@ -8,10 +8,10 @@ import { InitialFocus } from '@actual-app/components/initial-focus';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { send } from 'loot-core/platform/client/fetch';
import { q } from 'loot-core/shared/query';
+import { useSchedules } from '../../hooks/useSchedules';
import { type Modal as ModalType, pushModal } from '../../modals/modalsSlice';
import { useDispatch } from '../../redux';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';
diff --git a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
index 21822d06bf..df6ff15c0d 100644
--- a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
+++ b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
@@ -11,10 +11,6 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import {
- type ScheduleStatusType,
- type ScheduleStatuses,
-} from 'loot-core/client/data-hooks/schedules';
import { format as monthUtilFormat } from 'loot-core/shared/months';
import { getNormalisedString } from 'loot-core/shared/normalisation';
import { getScheduledAmount } from 'loot-core/shared/schedules';
@@ -31,6 +27,10 @@ import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { usePayees } from '@desktop-client/hooks/usePayees';
+import {
+ type ScheduleStatusType,
+ type ScheduleStatuses,
+} from '@desktop-client/hooks/useSchedules';
type SchedulesTableProps = {
isLoading?: boolean;
diff --git a/packages/desktop-client/src/components/schedules/StatusBadge.tsx b/packages/desktop-client/src/components/schedules/StatusBadge.tsx
index d9460a420b..ae910c8c65 100644
--- a/packages/desktop-client/src/components/schedules/StatusBadge.tsx
+++ b/packages/desktop-client/src/components/schedules/StatusBadge.tsx
@@ -14,9 +14,10 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { type ScheduleStatusType } from 'loot-core/client/data-hooks/schedules';
import { titleFirst } from 'loot-core/shared/util';
+import { type ScheduleStatusType } from '../../hooks/useSchedules';
+
// Consists of Schedule Statuses + Transaction statuses
export type StatusTypes =
| ScheduleStatusType
diff --git a/packages/desktop-client/src/components/schedules/index.tsx b/packages/desktop-client/src/components/schedules/index.tsx
index 2194d92c2f..285adf86ef 100644
--- a/packages/desktop-client/src/components/schedules/index.tsx
+++ b/packages/desktop-client/src/components/schedules/index.tsx
@@ -5,11 +5,11 @@ import { Button } from '@actual-app/components/button';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { send } from 'loot-core/platform/client/fetch';
import { q } from 'loot-core/shared/query';
import { type ScheduleEntity } from 'loot-core/types/models';
+import { useSchedules } from '../../hooks/useSchedules';
import { pushModal } from '../../modals/modalsSlice';
import { useDispatch } from '../../redux';
import { Search } from '../common/Search';
diff --git a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
index 992473100d..74b957aca8 100644
--- a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
+++ b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
@@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next';
import { Menu } from '@actual-app/components/menu';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { validForTransfer } from 'loot-core/client/transfer';
import { q } from 'loot-core/shared/query';
import {
@@ -18,6 +17,7 @@ import { pushModal } from '../../modals/modalsSlice';
import { useDispatch } from '../../redux';
import { SelectedItemsButton } from '../table';
+import { useSchedules } from '@desktop-client/hooks/useSchedules';
import { useSelectedItems } from '@desktop-client/hooks/useSelected';
type SelectedTransactionsButtonProps = {
diff --git a/packages/desktop-client/src/components/transactions/TransactionMenu.tsx b/packages/desktop-client/src/components/transactions/TransactionMenu.tsx
index 95cd9cc493..ac9082513a 100644
--- a/packages/desktop-client/src/components/transactions/TransactionMenu.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionMenu.tsx
@@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next';
import { Menu } from '@actual-app/components/menu';
-import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { q } from 'loot-core/shared/query';
import {
scheduleIsRecurring,
@@ -12,6 +11,7 @@ import {
import { isPreviewId } from 'loot-core/shared/transactions';
import { type TransactionEntity } from 'loot-core/types/models';
+import { useSchedules } from '../../hooks/useSchedules';
import { pushModal } from '../../modals/modalsSlice';
import { useDispatch } from '../../redux';
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
index daadc3c17f..4193d9ffc1 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
@@ -5,7 +5,6 @@ import userEvent from '@testing-library/user-event';
import { format as formatDate, parse as parseDate } from 'date-fns';
import { v4 as uuidv4 } from 'uuid';
-import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import {
generateTransaction,
@@ -33,6 +32,7 @@ import { TestProvider } from '../../redux/mock';
import { TransactionTable } from './TransactionsTable';
+import { SchedulesProvider } from '@desktop-client/hooks/useCachedSchedules';
import { SelectedProviderWithItems } from '@desktop-client/hooks/useSelected';
import { SplitsExpandedProvider } from '@desktop-client/hooks/useSplitsExpanded';
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index ebadb6d112..a997f3cd4d 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -43,7 +43,6 @@ import { View } from '@actual-app/components/view';
import { css } from '@emotion/css';
import { format as formatDate, parseISO } from 'date-fns';
-import { useCachedSchedules } from 'loot-core/client/data-hooks/schedules';
import * as monthUtils from 'loot-core/shared/months';
import {
addSplitTransaction,
@@ -70,11 +69,6 @@ import {
type TransactionEntity,
} from 'loot-core/types/models';
-import { useContextMenu } from '../../hooks/useContextMenu';
-import { useDisplayPayee } from '../../hooks/useDisplayPayee';
-import { useMergedRefs } from '../../hooks/useMergedRefs';
-import { usePrevious } from '../../hooks/usePrevious';
-import { useProperFocus } from '../../hooks/useProperFocus';
import { useSelectedDispatch, useSelectedItems } from '../../hooks/useSelected';
import {
type SplitsExpandedContextValue,
@@ -116,6 +110,12 @@ import {
} from './table/utils';
import { TransactionMenu } from './TransactionMenu';
+import { useCachedSchedules } from '@desktop-client/hooks/useCachedSchedules';
+import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
+import { useDisplayPayee } from '@desktop-client/hooks/useDisplayPayee';
+import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
+import { usePrevious } from '@desktop-client/hooks/usePrevious';
+import { useProperFocus } from '@desktop-client/hooks/useProperFocus';
import { pushModal } from '@desktop-client/modals/modalsSlice';
import { addNotification } from '@desktop-client/notifications/notificationsSlice';
import {
diff --git a/packages/desktop-client/src/components/util/GenericInput.jsx b/packages/desktop-client/src/components/util/GenericInput.jsx
index 7fa30935d1..8fa73442b1 100644
--- a/packages/desktop-client/src/components/util/GenericInput.jsx
+++ b/packages/desktop-client/src/components/util/GenericInput.jsx
@@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next';
import { Input } from '@actual-app/components/input';
import { View } from '@actual-app/components/view';
-import { useReports } from 'loot-core/client/data-hooks/reports';
import { getMonthYearFormat } from 'loot-core/shared/months';
import { integerToAmount, amountToInteger } from 'loot-core/shared/util';
@@ -24,6 +23,7 @@ import { PercentInput } from './PercentInput';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
+import { useReports } from '@desktop-client/hooks/useReports';
export function GenericInput({
field,
diff --git a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
index 43d4b7efbf..f100c0389d 100644
--- a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
+++ b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
@@ -1,6 +1,5 @@
import { useCallback, useMemo } from 'react';
-import { usePreviewTransactions } from 'loot-core/client/data-hooks/transactions';
import { accountBalance } from 'loot-core/client/queries';
import { groupById } from 'loot-core/shared/util';
import {
@@ -12,6 +11,7 @@ import {
import { useAccounts } from './useAccounts';
import { usePayees } from './usePayees';
+import { usePreviewTransactions } from './usePreviewTransactions';
import { useSheetValue } from '@desktop-client/components/spreadsheet/useSheetValue';
diff --git a/packages/desktop-client/src/hooks/useCachedSchedules.tsx b/packages/desktop-client/src/hooks/useCachedSchedules.tsx
new file mode 100644
index 0000000000..d1f1576613
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useCachedSchedules.tsx
@@ -0,0 +1,40 @@
+import React, {
+ createContext,
+ type PropsWithChildren,
+ useContext,
+} from 'react';
+
+import {
+ type UseSchedulesResult,
+ type UseSchedulesProps,
+ useSchedules,
+} from './useSchedules';
+
+type SchedulesContextValue = UseSchedulesResult;
+
+const SchedulesContext = createContext<SchedulesContextValue | undefined>(
+ undefined,
+);
+
+type SchedulesProviderProps = PropsWithChildren<{
+ query?: UseSchedulesProps['query'];
+}>;
+
+export function SchedulesProvider({ query, children }: SchedulesProviderProps) {
+ const data = useSchedules({ query });
+ return (
+ <SchedulesContext.Provider value={data}>
+ {children}
+ </SchedulesContext.Provider>
+ );
+}
+
+export function useCachedSchedules() {
+ const context = useContext(SchedulesContext);
+ if (!context) {
+ throw new Error(
+ 'useCachedSchedules must be used within a SchedulesProvider',
+ );
+ }
+ return context;
+}
diff --git a/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts b/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts
index 59ac5f2699..da7a8e4b48 100644
--- a/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts
+++ b/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts
@@ -1,6 +1,5 @@
import { useCallback, useMemo } from 'react';
-import { usePreviewTransactions } from 'loot-core/client/data-hooks/transactions';
import { categoryBalance } from 'loot-core/client/queries';
import * as monthUtils from 'loot-core/shared/months';
import {
@@ -10,6 +9,7 @@ import {
import { useCategory } from './useCategory';
import { useCategoryScheduleGoalTemplates } from './useCategoryScheduleGoalTemplates';
+import { usePreviewTransactions } from './usePreviewTransactions';
import { useSheetValue } from '@desktop-client/components/spreadsheet/useSheetValue';
diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
index 4aa4cc7a6d..c8cbc7da1c 100644
--- a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
+++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
@@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next';
import { type TFunction } from 'i18next';
-import { type ScheduleStatusType } from 'loot-core/client/data-hooks/schedules';
import * as monthUtils from 'loot-core/shared/months';
import {
type CategoryEntity,
@@ -12,6 +11,7 @@ import {
import { useCategoryScheduleGoalTemplates } from './useCategoryScheduleGoalTemplates';
import { useLocale } from './useLocale';
+import { type ScheduleStatusType } from './useSchedules';
type UseCategoryScheduleGoalTemplateProps = {
category: CategoryEntity;
diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts
index f87c421568..03328b5443 100644
--- a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts
+++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts
@@ -1,16 +1,16 @@
import { useMemo } from 'react';
-import {
- type ScheduleStatuses,
- type ScheduleStatusLabels,
- useCachedSchedules,
-} from 'loot-core/client/data-hooks/schedules';
import {
type ScheduleEntity,
type CategoryEntity,
} from 'loot-core/types/models';
+import { useCachedSchedules } from './useCachedSchedules';
import { useFeatureFlag } from './useFeatureFlag';
+import {
+ type ScheduleStatuses,
+ type ScheduleStatusLabels,
+} from './useSchedules';
type ScheduleGoalDefinition = {
type: 'schedule';
diff --git a/packages/loot-core/src/client/data-hooks/dashboard.ts b/packages/desktop-client/src/hooks/useDashboard.ts
similarity index 65%
rename from packages/loot-core/src/client/data-hooks/dashboard.ts
rename to packages/desktop-client/src/hooks/useDashboard.ts
index 58afcf2812..4bf88ba965 100644
--- a/packages/loot-core/src/client/data-hooks/dashboard.ts
+++ b/packages/desktop-client/src/hooks/useDashboard.ts
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
-import { q } from '../../shared/query';
-import { type Widget } from '../../types/models';
-import { useQuery } from '../query-hooks';
+import { useQuery } from 'loot-core/client/query-hooks';
+import { q } from 'loot-core/shared/query';
+import { type Widget } from 'loot-core/types/models';
export function useDashboard() {
const { data: queryData, isLoading } = useQuery<Widget>(
diff --git a/packages/desktop-client/src/hooks/useDisplayPayee.ts b/packages/desktop-client/src/hooks/useDisplayPayee.ts
index ab2609b523..d412ab1094 100644
--- a/packages/desktop-client/src/hooks/useDisplayPayee.ts
+++ b/packages/desktop-client/src/hooks/useDisplayPayee.ts
@@ -1,7 +1,6 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import { useTransactions } from 'loot-core/client/data-hooks/transactions';
import { q } from 'loot-core/shared/query';
import {
type AccountEntity,
@@ -12,6 +11,7 @@ import {
import { useAccounts } from './useAccounts';
import { usePayee } from './usePayee';
import { usePayees } from './usePayees';
+import { useTransactions } from './useTransactions';
type Counts = {
counts: Record<PayeeEntity['id'], number>;
diff --git a/packages/loot-core/src/client/data-hooks/transactions.ts b/packages/desktop-client/src/hooks/usePreviewTransactions.ts
similarity index 86%
rename from packages/loot-core/src/client/data-hooks/transactions.ts
rename to packages/desktop-client/src/hooks/usePreviewTransactions.ts
index 3a4cc1aa7c..3db5cb2ba9 100644
--- a/packages/loot-core/src/client/data-hooks/transactions.ts
+++ b/packages/desktop-client/src/hooks/usePreviewTransactions.ts
@@ -1,30 +1,28 @@
import { useEffect, useRef, useState, useMemo, useCallback } from 'react';
-// eslint-disable-next-line no-restricted-imports -- fix me -- do not import @actual-app/web in loot-core
-import { useSyncedPref } from '@actual-app/web/src/hooks/useSyncedPref';
import * as d from 'date-fns';
-import debounce from 'lodash/debounce';
-import { send } from '../../platform/client/fetch';
-import { currentDay, addDays, parseDate } from '../../shared/months';
-import { type Query } from '../../shared/query';
+import { pagedQuery, type PagedQuery } from 'loot-core/client/query-helpers';
+import { send } from 'loot-core/platform/client/fetch';
+import { currentDay, addDays, parseDate } from 'loot-core/shared/months';
+import { type Query } from 'loot-core/shared/query';
import {
- getScheduledAmount,
- extractScheduleConds,
- getNextDate,
getUpcomingDays,
+ extractScheduleConds,
scheduleIsRecurring,
-} from '../../shared/schedules';
-import { ungroupTransactions } from '../../shared/transactions';
-import { type IntegerAmount } from '../../shared/util';
+ getNextDate,
+ getScheduledAmount,
+} from 'loot-core/shared/schedules';
+import { ungroupTransactions } from 'loot-core/shared/transactions';
+import { type IntegerAmount } from 'loot-core/shared/util';
import {
type ScheduleEntity,
type TransactionEntity,
-} from '../../types/models';
-import * as queries from '../queries';
-import { type PagedQuery, pagedQuery } from '../query-helpers';
+} from 'loot-core/types/models';
-import { type ScheduleStatuses, useCachedSchedules } from './schedules';
+import { useCachedSchedules } from './useCachedSchedules';
+import { type ScheduleStatuses } from './useSchedules';
+import { useSyncedPref } from './useSyncedPref';
// Mirrors the `splits` AQL option from the server
type TransactionSplitsOption = 'all' | 'inline' | 'grouped' | 'none';
@@ -406,54 +404,10 @@ export function usePreviewTransactions({
};
}
-type UseTransactionsSearchProps = {
- updateQuery: (updateFn: (searchQuery: Query) => Query) => void;
- resetQuery: () => void;
- dateFormat: string;
- delayMs?: number;
-};
-
-type UseTransactionsSearchResult = {
- isSearching: boolean;
- search: (searchText: string) => void;
-};
-
-export function useTransactionsSearch({
- updateQuery,
- resetQuery,
- dateFormat,
- delayMs = 150,
-}: UseTransactionsSearchProps): UseTransactionsSearchResult {
- const [isSearching, setIsSearching] = useState(false);
-
- const updateSearchQuery = useMemo(
- () =>
- debounce((searchText: string) => {
- if (searchText === '') {
- resetQuery();
- setIsSearching(false);
- } else if (searchText) {
- resetQuery();
- updateQuery(previousQuery =>
- queries.transactionsSearch(previousQuery, searchText, dateFormat),
- );
- setIsSearching(true);
- }
- }, delayMs),
- [dateFormat, delayMs, resetQuery, updateQuery],
- );
-
- useEffect(() => {
- return () => updateSearchQuery.cancel();
- }, [updateSearchQuery]);
-
- return {
- isSearching,
- search: updateSearchQuery,
- };
-}
-
-function isForPreview(schedule: ScheduleEntity, statuses: ScheduleStatuses) {
+export function isForPreview(
+ schedule: ScheduleEntity,
+ statuses: ScheduleStatuses,
+) {
const status = statuses.get(schedule.id);
return (
!schedule.completed &&
diff --git a/packages/desktop-client/src/hooks/useReport.ts b/packages/desktop-client/src/hooks/useReport.ts
new file mode 100644
index 0000000000..b590e046db
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useReport.ts
@@ -0,0 +1,15 @@
+import { useMemo } from 'react';
+
+import { useReports } from './useReports';
+
+export function useReport(id: string) {
+ const { data, isLoading } = useReports();
+
+ return useMemo(
+ () => ({
+ data: data.find(report => report.id === id),
+ isLoading,
+ }),
+ [data, id, isLoading],
+ );
+}
diff --git a/packages/loot-core/src/client/data-hooks/reports.ts b/packages/desktop-client/src/hooks/useReports.ts
similarity index 85%
rename from packages/loot-core/src/client/data-hooks/reports.ts
rename to packages/desktop-client/src/hooks/useReports.ts
index 53a4614c44..0f9280a5d5 100644
--- a/packages/loot-core/src/client/data-hooks/reports.ts
+++ b/packages/desktop-client/src/hooks/useReports.ts
@@ -1,11 +1,11 @@
import { useMemo } from 'react';
-import { q } from '../../shared/query';
+import { useQuery } from 'loot-core/client/query-hooks';
+import { q } from 'loot-core/shared/query';
import {
type CustomReportData,
type CustomReportEntity,
-} from '../../types/models';
-import { useQuery } from '../query-hooks';
+} from 'loot-core/types/models';
function toJS(rows: CustomReportData[]) {
const reports: CustomReportEntity[] = rows.map(row => {
@@ -61,12 +61,3 @@ export function useReports() {
[isLoading, queryData],
);
}
-
-export function useReport(id: string) {
- const { data, isLoading } = useReports();
-
- return {
- data: data.find(report => report.id === id),
- isLoading,
- };
-}
diff --git a/packages/desktop-client/src/hooks/useFilters.ts b/packages/desktop-client/src/hooks/useRuleConditionFilters.ts
similarity index 96%
rename from packages/desktop-client/src/hooks/useFilters.ts
rename to packages/desktop-client/src/hooks/useRuleConditionFilters.ts
index ccf2d23a4d..033c8c7dad 100644
--- a/packages/desktop-client/src/hooks/useFilters.ts
+++ b/packages/desktop-client/src/hooks/useRuleConditionFilters.ts
@@ -2,7 +2,7 @@ import { useCallback, useMemo, useState } from 'react';
import { type RuleConditionEntity } from 'loot-core/types/models';
-export function useFilters<T extends RuleConditionEntity>(
+export function useRuleConditionFilters<T extends RuleConditionEntity>(
initialConditions: T[] = [],
initialConditionsOp: 'and' | 'or' = 'and',
) {
diff --git a/packages/loot-core/src/client/data-hooks/schedules.tsx b/packages/desktop-client/src/hooks/useSchedules.ts
similarity index 72%
rename from packages/loot-core/src/client/data-hooks/schedules.tsx
rename to packages/desktop-client/src/hooks/useSchedules.ts
index ec648347f2..e538235fbe 100644
--- a/packages/loot-core/src/client/data-hooks/schedules.tsx
+++ b/packages/desktop-client/src/hooks/useSchedules.ts
@@ -1,29 +1,20 @@
-// @ts-strict-ignore
-import React, {
- createContext,
- type PropsWithChildren,
- useContext,
- useEffect,
- useRef,
- useState,
-} from 'react';
-
-// eslint-disable-next-line no-restricted-imports -- fix me -- do not import @actual-app/web in loot-core
-import { useSyncedPref } from '@actual-app/web/src/hooks/useSyncedPref';
-
-import { q, type Query } from '../../shared/query';
+import { useState, useRef, useEffect } from 'react';
+
+import { accountFilter } from 'loot-core/client/queries';
+import { liveQuery, type LiveQuery } from 'loot-core/client/query-helpers';
+import { q, type Query } from 'loot-core/shared/query';
import {
- getHasTransactionsQuery,
getStatus,
getStatusLabel,
-} from '../../shared/schedules';
-import {
- type AccountEntity,
- type ScheduleEntity,
- type TransactionEntity,
-} from '../../types/models';
-import { accountFilter } from '../queries';
-import { type LiveQuery, liveQuery } from '../query-helpers';
+ getHasTransactionsQuery,
+} from 'loot-core/shared/schedules';
+import type {
+ AccountEntity,
+ ScheduleEntity,
+ TransactionEntity,
+} from 'loot-core/types/models';
+
+import { useSyncedPref } from './useSyncedPref';
export type ScheduleStatusType = ReturnType<typeof getStatus>;
export type ScheduleStatuses = Map<ScheduleEntity['id'], ScheduleStatusType>;
@@ -33,12 +24,11 @@ export type ScheduleStatusLabels = Map<
ScheduleEntity['id'],
ScheduleStatusLabelType
>;
-
function loadStatuses(
schedules: readonly ScheduleEntity[],
onData: (data: ScheduleStatuses) => void,
onError: (error: Error) => void,
- upcomingLength: string,
+ upcomingLength: string = '7',
) {
return liveQuery<TransactionEntity>(getHasTransactionsQuery(schedules), {
onData: data => {
@@ -61,8 +51,7 @@ function loadStatuses(
onError,
});
}
-
-type UseSchedulesProps = {
+export type UseSchedulesProps = {
query?: Query;
};
type ScheduleData = {
@@ -70,7 +59,7 @@ type ScheduleData = {
statuses: ScheduleStatuses;
statusLabels: ScheduleStatusLabels;
};
-type UseSchedulesResult = ScheduleData & {
+export type UseSchedulesResult = ScheduleData & {
readonly isLoading: boolean;
readonly error?: Error;
};
@@ -126,7 +115,7 @@ export function useSchedules({
statusLabels: new Map(
[...statuses.keys()].map(key => [
key,
- getStatusLabel(statuses.get(key)),
+ getStatusLabel(statuses.get(key) || ''),
]),
),
});
@@ -153,36 +142,6 @@ export function useSchedules({
...data,
};
}
-
-type SchedulesContextValue = UseSchedulesResult;
-
-const SchedulesContext = createContext<SchedulesContextValue | undefined>(
- undefined,
-);
-
-type SchedulesProviderProps = PropsWithChildren<{
- query?: UseSchedulesProps['query'];
-}>;
-
-export function SchedulesProvider({ query, children }: SchedulesProviderProps) {
- const data = useSchedules({ query });
- return (
- <SchedulesContext.Provider value={data}>
- {children}
- </SchedulesContext.Provider>
- );
-}
-
-export function useCachedSchedules() {
- const context = useContext(SchedulesContext);
- if (!context) {
- throw new Error(
- 'useCachedSchedules must be used within a SchedulesProvider',
- );
- }
- return context;
-}
-
export function accountSchedulesQuery(
accountId?: AccountEntity['id'] | 'onbudget' | 'offbudget' | 'uncategorized',
) {
diff --git a/packages/loot-core/src/client/data-hooks/filters.ts b/packages/desktop-client/src/hooks/useTransactionFilters.ts
similarity index 75%
rename from packages/loot-core/src/client/data-hooks/filters.ts
rename to packages/desktop-client/src/hooks/useTransactionFilters.ts
index c23bc800b8..dd1d1de041 100644
--- a/packages/loot-core/src/client/data-hooks/filters.ts
+++ b/packages/desktop-client/src/hooks/useTransactionFilters.ts
@@ -1,9 +1,9 @@
// @ts-strict-ignore
import { useMemo } from 'react';
-import { q } from '../../shared/query';
-import { type TransactionFilterEntity } from '../../types/models';
-import { useQuery } from '../query-hooks';
+import { useQuery } from 'loot-core/client/query-hooks';
+import { q } from 'loot-core/shared/query';
+import { type TransactionFilterEntity } from 'loot-core/types/models';
function toJS(rows): TransactionFilterEntity[] {
const filters = rows.map(row => {
@@ -19,7 +19,7 @@ function toJS(rows): TransactionFilterEntity[] {
return filters;
}
-export function useFilters(): TransactionFilterEntity[] {
+export function useTransactionFilters(): TransactionFilterEntity[] {
const { data } = useQuery<TransactionFilterEntity>(
() => q('transaction_filters').select('*'),
[],
diff --git a/packages/desktop-client/src/hooks/useTransactions.ts b/packages/desktop-client/src/hooks/useTransactions.ts
new file mode 100644
index 0000000000..aad17d5674
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useTransactions.ts
@@ -0,0 +1,114 @@
+import { useState, useRef, useEffect, useCallback } from 'react';
+
+import { type PagedQuery, pagedQuery } from 'loot-core/client/query-helpers';
+import type { Query } from 'loot-core/shared/query';
+import type { TransactionEntity } from 'loot-core/types/models';
+
+type UseTransactionsProps = {
+ /**
+ * The Query class is immutable so it is important to memoize the query object
+ * to prevent unnecessary re-renders i.e. `useMemo`, `useState`, etc.
+ */
+ query?: Query;
+ options?: {
+ pageCount?: number;
+ };
+};
+type UseTransactionsResult = {
+ transactions: ReadonlyArray<TransactionEntity>;
+ isLoading: boolean;
+ error?: Error;
+ reload: () => void;
+ loadMore: () => void;
+ isLoadingMore: boolean;
+};
+
+export function useTransactions({
+ query,
+ options = { pageCount: 50 },
+}: UseTransactionsProps): UseTransactionsResult {
+ const [isLoading, setIsLoading] = useState(true);
+ const [isLoadingMore, setIsLoadingMore] = useState(false);
+ const [error, setError] = useState<Error | undefined>(undefined);
+ const [transactions, setTransactions] = useState<
+ ReadonlyArray<TransactionEntity>
+ >([]);
+
+ const pagedQueryRef = useRef<PagedQuery<TransactionEntity> | null>(null);
+
+ // We don't want to re-render if options changes.
+ // Putting options in a ref will prevent that and
+ // allow us to use the latest options on next render.
+ const optionsRef = useRef(options);
+ optionsRef.current = options;
+
+ useEffect(() => {
+ let isUnmounted = false;
+
+ setError(undefined);
+
+ if (!query) {
+ return;
+ }
+
+ function onError(error: Error) {
+ if (!isUnmounted) {
+ setError(error);
+ setIsLoading(false);
+ }
+ }
+
+ if (query.state.table !== 'transactions') {
+ onError(new Error('Query must be a transactions query.'));
+ return;
+ }
+
+ setIsLoading(true);
+
+ pagedQueryRef.current = pagedQuery<TransactionEntity>(query, {
+ onData: data => {
+ if (!isUnmounted) {
+ setTransactions(data);
+ setIsLoading(false);
+ }
+ },
+ onError,
+ options: optionsRef.current.pageCount
+ ? { pageCount: optionsRef.current.pageCount }
+ : {},
+ });
+
+ return () => {
+ isUnmounted = true;
+ pagedQueryRef.current?.unsubscribe();
+ };
+ }, [query]);
+
+ const loadMore = useCallback(async () => {
+ if (!pagedQueryRef.current) {
+ return;
+ }
+
+ setIsLoadingMore(true);
+
+ await pagedQueryRef.current
+ .fetchNext()
+ .catch(setError)
+ .finally(() => {
+ setIsLoadingMore(false);
+ });
+ }, []);
+
+ const reload = useCallback(() => {
+ pagedQueryRef.current?.run();
+ }, []);
+
+ return {
+ transactions,
+ isLoading,
+ ...(error && { error }),
+ reload,
+ loadMore,
+ isLoadingMore,
+ };
+}
diff --git a/packages/desktop-client/src/hooks/useTransactionsSearch.ts b/packages/desktop-client/src/hooks/useTransactionsSearch.ts
new file mode 100644
index 0000000000..ef787c7f3e
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useTransactionsSearch.ts
@@ -0,0 +1,52 @@
+import { useState, useMemo, useEffect } from 'react';
+
+import { debounce } from 'lodash';
+
+import * as queries from 'loot-core/client/queries';
+import type { Query } from 'loot-core/shared/query';
+
+type UseTransactionsSearchProps = {
+ updateQuery: (updateFn: (searchQuery: Query) => Query) => void;
+ resetQuery: () => void;
+ dateFormat: string;
+ delayMs?: number;
+};
+type UseTransactionsSearchResult = {
+ isSearching: boolean;
+ search: (searchText: string) => void;
+};
+
+export function useTransactionsSearch({
+ updateQuery,
+ resetQuery,
+ dateFormat,
+ delayMs = 150,
+}: UseTransactionsSearchProps): UseTransactionsSearchResult {
+ const [isSearching, setIsSearching] = useState(false);
+
+ const updateSearchQuery = useMemo(
+ () =>
+ debounce((searchText: string) => {
+ if (searchText === '') {
+ resetQuery();
+ setIsSearching(false);
+ } else if (searchText) {
+ resetQuery();
+ updateQuery(previousQuery =>
+ queries.transactionsSearch(previousQuery, searchText, dateFormat),
+ );
+ setIsSearching(true);
+ }
+ }, delayMs),
+ [dateFormat, delayMs, resetQuery, updateQuery],
+ );
+
+ useEffect(() => {
+ return () => updateSearchQuery.cancel();
+ }, [updateSearchQuery]);
+
+ return {
+ isSearching,
+ search: updateSearchQuery,
+ };
+}
diff --git a/packages/loot-core/src/client/data-hooks/widget.ts b/packages/desktop-client/src/hooks/useWidget.ts
similarity index 69%
rename from packages/loot-core/src/client/data-hooks/widget.ts
rename to packages/desktop-client/src/hooks/useWidget.ts
index 93297755a8..baf544928d 100644
--- a/packages/loot-core/src/client/data-hooks/widget.ts
+++ b/packages/desktop-client/src/hooks/useWidget.ts
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
-import { q } from '../../shared/query';
-import { type Widget } from '../../types/models';
-import { useQuery } from '../query-hooks';
+import { useQuery } from 'loot-core/client/query-hooks';
+import { q } from 'loot-core/shared/query';
+import { type Widget } from 'loot-core/types/models';
export function useWidget<W extends Widget>(id: W['id'], type: W['type']) {
const { data = [], isLoading } = useQuery<W>(
diff --git a/packages/loot-core/src/shared/schedules.ts b/packages/loot-core/src/shared/schedules.ts
index 6d050925df..d11f0c11db 100644
--- a/packages/loot-core/src/shared/schedules.ts
+++ b/packages/loot-core/src/shared/schedules.ts
@@ -12,7 +12,7 @@ export function getStatus(
nextDate: string,
completed: boolean,
hasTrans: boolean,
- upcomingLength: string,
+ upcomingLength: string = '7',
) {
const upcomingDays = getUpcomingDays(upcomingLength);
const today = monthUtils.currentDay();
diff --git a/upcoming-release-notes/4828.md b/upcoming-release-notes/4828.md
new file mode 100644
index 0000000000..df7944e733
--- /dev/null
+++ b/upcoming-release-notes/4828.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+Move loot-core/client/data-hooks over to desktop-client package