Skip to content

Commit

Permalink
Queries slice
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Dec 19, 2024
1 parent ccaf3d7 commit 6c0c9ff
Show file tree
Hide file tree
Showing 39 changed files with 1,094 additions and 851 deletions.
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/ManageRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import React, {
import { useTranslation } from 'react-i18next';

import { useSchedules } from 'loot-core/client/data-hooks/schedules';
import { initiallyLoadPayees } from 'loot-core/client/queries/queriesSlice';
import { q } from 'loot-core/shared/query';
import { pushModal } from 'loot-core/src/client/actions/modals';
import { initiallyLoadPayees } from 'loot-core/src/client/actions/queries';
import { send } from 'loot-core/src/platform/client/fetch';
import * as undo from 'loot-core/src/platform/client/undo';
import { getNormalisedString } from 'loot-core/src/shared/normalisation';
Expand Down
24 changes: 13 additions & 11 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ import { t } from 'i18next';
import { v4 as uuidv4 } from 'uuid';

import { unlinkAccount } from 'loot-core/client/accounts/accountSlice';
import {
openAccountCloseModal,
pushModal,
replaceModal,
syncAndDownload,
} from 'loot-core/client/actions';
import {
createPayee,
getPayees,
initiallyLoadPayees,
markAccountRead,
openAccountCloseModal,
pushModal,
reopenAccount,
replaceModal,
syncAndDownload,
updateAccount,
updateNewTransactions,
} from 'loot-core/client/actions';
} from 'loot-core/client/queries/queriesSlice';
import { type AppDispatch } from 'loot-core/client/store';
import { validForTransfer } from 'loot-core/client/transfer';
import { type UndoState } from 'loot-core/server/undo';
Expand Down Expand Up @@ -500,7 +502,7 @@ class AccountInternal extends PureComponent<
else this.updateQuery(query);

if (this.props.accountId) {
this.props.dispatch(markAccountRead(this.props.accountId));
this.props.dispatch(markAccountRead({ accountId: this.props.accountId }));
}
};

Expand Down Expand Up @@ -684,7 +686,7 @@ class AccountInternal extends PureComponent<
}
});

this.props.dispatch(updateNewTransactions(updatedTransaction.id));
this.props.dispatch(updateNewTransactions({ id: updatedTransaction.id }));
};

canCalculateBalance = () => {
Expand Down Expand Up @@ -736,7 +738,7 @@ class AccountInternal extends PureComponent<
const account = this.props.accounts.find(
account => account.id === this.props.accountId,
);
this.props.dispatch(updateAccount({ ...account, name }));
this.props.dispatch(updateAccount({ account: { ...account, name } }));
this.setState({ editingName: false, nameError: '' });
}
};
Expand Down Expand Up @@ -784,7 +786,7 @@ class AccountInternal extends PureComponent<
this.props.dispatch(openAccountCloseModal(accountId));
break;
case 'reopen':
this.props.dispatch(reopenAccount(accountId));
this.props.dispatch(reopenAccount({ accountId }));
break;
case 'export':
const accountName = this.getAccountTitle(account, accountId);
Expand Down Expand Up @@ -899,7 +901,7 @@ class AccountInternal extends PureComponent<
onCreatePayee = (name: string) => {
const trimmed = name.trim();
if (trimmed !== '') {
return this.props.dispatch(createPayee(name));
return this.props.dispatch(createPayee({ name })).unwrap();
}
return null;
};
Expand Down Expand Up @@ -1277,7 +1279,7 @@ class AccountInternal extends PureComponent<
const onConfirmTransfer = async (ids: string[]) => {
this.setState({ workingHard: true });

const payees = await this.props.dispatch(getPayees());
const payees = await this.props.dispatch(getPayees()).unwrap();
const { data: transactions } = await runQuery(
q('transactions')
.filter({ id: { $oneof: ids } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { Trans, useTranslation } from 'react-i18next';

import { css, cx } from '@emotion/css';

import { createPayee } from 'loot-core/src/client/actions/queries';
import { getActivePayees } from 'loot-core/src/client/reducers/queries';
import {
createPayee,
getActivePayees,
} from 'loot-core/client/queries/queriesSlice';
import { getNormalisedString } from 'loot-core/src/shared/normalisation';
import {
type AccountEntity,
Expand Down Expand Up @@ -326,7 +328,8 @@ export function PayeeAutocomplete({
if (!clearOnBlur) {
onSelect?.(makeNew(idOrIds, rawInputValue), rawInputValue);
} else {
const create = payeeName => dispatch(createPayee(payeeName));
const create = payeeName =>
dispatch(createPayee({ name: payeeName })).unwrap();

if (Array.isArray(idOrIds)) {
idOrIds = await Promise.all(
Expand Down
52 changes: 31 additions & 21 deletions packages/desktop-client/src/components/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { memo, useMemo, useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import {
addNotification,
applyBudgetAction,
createCategory,
createGroup,
Expand All @@ -12,10 +11,10 @@ import {
getCategories,
moveCategory,
moveCategoryGroup,
pushModal,
updateCategory,
updateGroup,
} from 'loot-core/src/client/actions';
} from 'loot-core/client/queries/queriesSlice';
import { addNotification, pushModal } from 'loot-core/src/client/actions';
import { useSpreadsheet } from 'loot-core/src/client/SpreadsheetProvider';
import { send, listen } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
Expand Down Expand Up @@ -201,15 +200,15 @@ function BudgetInner(props: BudgetInnerProps) {

if (category.id === 'new') {
dispatch(
createCategory(
category.name,
category.cat_group,
category.is_income,
category.hidden,
),
createCategory({
name: category.name,
groupId: category.cat_group,
isIncome: category.is_income,
isHidden: category.hidden,
}),
);
} else {
dispatch(updateCategory(category));
dispatch(updateCategory({ category }));
}
};

Expand All @@ -222,21 +221,21 @@ function BudgetInner(props: BudgetInnerProps) {
category: id,
onDelete: transferCategory => {
if (id !== transferCategory) {
dispatch(deleteCategory(id, transferCategory));
dispatch(deleteCategory({ id, transferId: transferCategory }));
}
},
}),
);
} else {
dispatch(deleteCategory(id));
dispatch(deleteCategory({ id }));
}
};

const onSaveGroup = group => {
if (group.id === 'new') {
dispatch(createGroup(group.name));
dispatch(createGroup({ name: group.name }));
} else {
dispatch(updateGroup(group));
dispatch(updateGroup({ group }));
}
};

Expand All @@ -256,26 +255,29 @@ function BudgetInner(props: BudgetInnerProps) {
pushModal('confirm-category-delete', {
group: id,
onDelete: transferCategory => {
dispatch(deleteGroup(id, transferCategory));
dispatch(deleteGroup({ id, transferId: transferCategory }));
},
}),
);
} else {
dispatch(deleteGroup(id));
dispatch(deleteGroup({ id }));
}
};

const onApplyBudgetTemplatesInGroup = async categories => {
dispatch(
applyBudgetAction(startMonth, 'apply-multiple-templates', {
applyBudgetAction({
month: startMonth,
categories,
type: 'apply-multiple-templates',
args: {
categories,
},
}),
);
};

const onBudgetAction = (month, type, args) => {
dispatch(applyBudgetAction(month, type, args));
dispatch(applyBudgetAction({ month, type, args }));
};

const onShowActivity = (categoryId, month) => {
Expand Down Expand Up @@ -314,11 +316,19 @@ function BudgetInner(props: BudgetInnerProps) {
return;
}

dispatch(moveCategory(sortInfo.id, sortInfo.groupId, sortInfo.targetId));
dispatch(
moveCategory({
id: sortInfo.id,
groupId: sortInfo.groupId,
targetId: sortInfo.targetId,
}),
);
};

const onReorderGroup = async sortInfo => {
dispatch(moveCategoryGroup(sortInfo.id, sortInfo.targetId));
dispatch(
moveCategoryGroup({ id: sortInfo.id, targetId: sortInfo.targetId }),
);
};

const onToggleCollapse = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import React, {

import {
collapseModals,
getPayees,
markAccountRead,
openAccountCloseModal,
pushModal,
reopenAccount,
syncAndDownload,
updateAccount,
} from 'loot-core/client/actions';
import {
accountSchedulesQuery,
Expand All @@ -25,6 +21,12 @@ import {
useTransactionsSearch,
} from 'loot-core/client/data-hooks/transactions';
import * as queries from 'loot-core/client/queries';
import {
getPayees,
markAccountRead,
reopenAccount,
updateAccount,
} from 'loot-core/client/queries/queriesSlice';
import { listen, send } from 'loot-core/platform/client/fetch';
import { type Query } from 'loot-core/shared/query';
import { isPreviewId } from 'loot-core/shared/transactions';
Expand Down Expand Up @@ -113,7 +115,7 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {

const onSave = useCallback(
(account: AccountEntity) => {
dispatch(updateAccount(account));
dispatch(updateAccount({ account }));
},
[dispatch],
);
Expand All @@ -140,7 +142,7 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {
}, [account.id, dispatch]);

const onReopenAccount = useCallback(() => {
dispatch(reopenAccount(account.id));
dispatch(reopenAccount({ accountId: account.id }));
}, [account.id, dispatch]);

const onClick = useCallback(() => {
Expand Down Expand Up @@ -264,7 +266,7 @@ function TransactionListWithPreviews({

useEffect(() => {
if (accountId) {
dispatch(markAccountRead(accountId));
dispatch(markAccountRead({ accountId }));
}
}, [accountId, dispatch]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useCallback, useEffect, useState } from 'react';

import { getPayees } from 'loot-core/client/actions';
import {
useTransactions,
useTransactionsSearch,
} from 'loot-core/client/data-hooks/transactions';
import * as queries from 'loot-core/client/queries';
import { getPayees } from 'loot-core/client/queries/queriesSlice';
import { listen } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
Expand Down
Loading

0 comments on commit 6c0c9ff

Please sign in to comment.