mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
Use javascript proxy to encapsulate the calls to loot core server via connection package's send
This commit is contained in:
@@ -10,7 +10,7 @@ import { Text } from '@actual-app/components/text';
|
||||
import { theme } from '@actual-app/components/theme';
|
||||
import { View } from '@actual-app/components/view';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { send, server } from 'loot-core/platform/client/connection';
|
||||
import * as undo from 'loot-core/platform/client/undo';
|
||||
import { getNormalisedString } from 'loot-core/shared/normalisation';
|
||||
import { q } from 'loot-core/shared/query';
|
||||
@@ -176,7 +176,7 @@ export function ManageRules({
|
||||
|
||||
let loadedRules = null;
|
||||
if (payeeId) {
|
||||
loadedRules = await send('payees-get-rules', {
|
||||
loadedRules = await server.getPayeeRules({
|
||||
id: payeeId,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Text } from '@actual-app/components/text';
|
||||
import { theme } from '@actual-app/components/theme';
|
||||
import { View } from '@actual-app/components/view';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { server } from 'loot-core/platform/client/connection';
|
||||
import type { PayeeEntity } from 'loot-core/types/models';
|
||||
|
||||
import { MobileBackButton } from '@desktop-client/components/mobile/MobileBackButton';
|
||||
@@ -58,7 +58,7 @@ export function MobilePayeeEditPage() {
|
||||
}
|
||||
|
||||
try {
|
||||
await send('payees-batch-change', {
|
||||
await server.batchChangePayees({
|
||||
updated: [{ id: payee.id, name: editedPayeeName.trim() }],
|
||||
});
|
||||
showUndoNotification({
|
||||
|
||||
@@ -5,7 +5,7 @@ import { styles } from '@actual-app/components/styles';
|
||||
import { theme } from '@actual-app/components/theme';
|
||||
import { View } from '@actual-app/components/view';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { server } from 'loot-core/platform/client/connection';
|
||||
import { getNormalisedString } from 'loot-core/shared/normalisation';
|
||||
import type { PayeeEntity, RuleEntity } from 'loot-core/types/models';
|
||||
|
||||
@@ -52,7 +52,7 @@ export function MobilePayeesPage() {
|
||||
// View associated rules for the payee
|
||||
if ((ruleCounts.get(payee.id) ?? 0) > 0) {
|
||||
try {
|
||||
const associatedRules: RuleEntity[] = await send('payees-get-rules', {
|
||||
const associatedRules: RuleEntity[] = await server.getPayeeRules({
|
||||
id: payee.id,
|
||||
});
|
||||
const ruleIds = associatedRules.map(rule => rule.id).join(',');
|
||||
@@ -88,7 +88,7 @@ export function MobilePayeesPage() {
|
||||
const handlePayeeDelete = useCallback(
|
||||
async (payee: PayeeEntity) => {
|
||||
try {
|
||||
await send('payees-batch-change', { deleted: [{ id: payee.id }] });
|
||||
await server.batchChangePayees({ deleted: [{ id: payee.id }] });
|
||||
showUndoNotification({
|
||||
message: t('Payee "{{name}}" deleted successfully', {
|
||||
name: payee.name,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Text } from '@actual-app/components/text';
|
||||
import { theme } from '@actual-app/components/theme';
|
||||
import { View } from '@actual-app/components/view';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { send, server } from 'loot-core/platform/client/connection';
|
||||
import type { PayeeEntity } from 'loot-core/types/models';
|
||||
import type { TransObjectLiteral } from 'loot-core/types/util';
|
||||
|
||||
@@ -59,7 +59,7 @@ export function MergeUnusedPayeesModal({
|
||||
|
||||
const onMerge = useCallback(
|
||||
async (targetPayee: PayeeEntity) => {
|
||||
await send('payees-merge', {
|
||||
await server.mergePayees({
|
||||
targetId: targetPayee.id,
|
||||
mergeIds: payees.map(payee => payee.id),
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
|
||||
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { listen, send } from 'loot-core/platform/client/connection';
|
||||
import { listen, server } from 'loot-core/platform/client/connection';
|
||||
import * as undo from 'loot-core/platform/client/undo';
|
||||
import type { UndoState } from 'loot-core/server/undo';
|
||||
import { applyChanges } from 'loot-core/shared/util';
|
||||
@@ -112,14 +112,14 @@ export function ManagePayeesWithData({
|
||||
orphanedPayees={orphanedPayees}
|
||||
initialSelectedIds={initialSelectedIds}
|
||||
onBatchChange={async (changes: Diff<PayeeEntity>) => {
|
||||
await send('payees-batch-change', changes);
|
||||
await server.batchChangePayees(changes);
|
||||
queryClient.setQueryData(
|
||||
payeeQueries.listOrphaned().queryKey,
|
||||
existing => applyChanges(changes, existing ?? []),
|
||||
);
|
||||
}}
|
||||
onMerge={async ([targetId, ...mergeIds]) => {
|
||||
await send('payees-merge', { targetId, mergeIds });
|
||||
await server.mergePayees({ targetId, mergeIds });
|
||||
|
||||
const targetIdIsOrphan = orphanedPayees
|
||||
.map(o => o.id)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { server } from 'loot-core/platform/client/connection';
|
||||
import type { LocationCoordinates } from 'loot-core/shared/location-utils';
|
||||
import type {
|
||||
NearbyPayeeEntity,
|
||||
@@ -68,7 +68,7 @@ export class SendApiLocationClient implements LocationApiClient {
|
||||
payeeId: string,
|
||||
coordinates: LocationCoordinates,
|
||||
): Promise<string> {
|
||||
return await send('payee-location-create', {
|
||||
return await server.createPayeeLocation({
|
||||
payeeId,
|
||||
latitude: coordinates.latitude,
|
||||
longitude: coordinates.longitude,
|
||||
@@ -76,18 +76,18 @@ export class SendApiLocationClient implements LocationApiClient {
|
||||
}
|
||||
|
||||
async getLocations(payeeId: string): Promise<PayeeLocationEntity[]> {
|
||||
return await send('payee-locations-get', { payeeId });
|
||||
return await server.getPayeeLocations({ payeeId });
|
||||
}
|
||||
|
||||
async deleteLocation(locationId: string): Promise<void> {
|
||||
await send('payee-location-delete', { id: locationId });
|
||||
await server.deletePayeeLocation({ id: locationId });
|
||||
}
|
||||
|
||||
async getNearbyPayees(
|
||||
coordinates: LocationCoordinates,
|
||||
maxDistance: number,
|
||||
): Promise<NearbyPayeeEntity[]> {
|
||||
const result = await send('payees-get-nearby', {
|
||||
const result = await server.getNearbyPayees({
|
||||
latitude: coordinates.latitude,
|
||||
longitude: coordinates.longitude,
|
||||
maxDistance,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import type { QueryClient, QueryKey } from '@tanstack/react-query';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { server } from 'loot-core/platform/client/connection';
|
||||
import type { PayeeEntity } from 'loot-core/types/models';
|
||||
|
||||
import { locationService } from './location';
|
||||
@@ -99,7 +99,7 @@ export function useCreatePayeeMutation() {
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ name }: CreatePayeePayload) => {
|
||||
const id: PayeeEntity['id'] = await send('payee-create', {
|
||||
const id: PayeeEntity['id'] = await server.createPayee({
|
||||
name: name.trim(),
|
||||
});
|
||||
return id;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { queryOptions } from '@tanstack/react-query';
|
||||
import { t } from 'i18next';
|
||||
import memoizeOne from 'memoize-one';
|
||||
|
||||
import { send } from 'loot-core/platform/client/connection';
|
||||
import { server } from 'loot-core/platform/client/connection';
|
||||
import { groupById } from 'loot-core/shared/util';
|
||||
import type {
|
||||
AccountEntity,
|
||||
@@ -21,7 +21,7 @@ export const payeeQueries = {
|
||||
queryOptions<PayeeEntity[]>({
|
||||
queryKey: [...payeeQueries.lists()],
|
||||
queryFn: async () => {
|
||||
const payees: PayeeEntity[] = (await send('payees-get')) ?? [];
|
||||
const payees: PayeeEntity[] = (await server.getPayees()) ?? [];
|
||||
return translatePayees(payees);
|
||||
},
|
||||
placeholderData: [],
|
||||
@@ -32,7 +32,7 @@ export const payeeQueries = {
|
||||
queryOptions<PayeeEntity[]>({
|
||||
queryKey: [...payeeQueries.lists(), 'common'],
|
||||
queryFn: async () => {
|
||||
const payees: PayeeEntity[] = (await send('common-payees-get')) ?? [];
|
||||
const payees: PayeeEntity[] = (await server.getCommonPayees()) ?? [];
|
||||
return translatePayees(payees);
|
||||
},
|
||||
placeholderData: [],
|
||||
@@ -44,7 +44,7 @@ export const payeeQueries = {
|
||||
queryKey: [...payeeQueries.lists(), 'orphaned'],
|
||||
queryFn: async () => {
|
||||
const payees: Pick<PayeeEntity, 'id'>[] =
|
||||
(await send('payees-get-orphaned')) ?? [];
|
||||
(await server.getOrphanedPayees()) ?? [];
|
||||
return payees;
|
||||
},
|
||||
placeholderData: [],
|
||||
@@ -55,7 +55,7 @@ export const payeeQueries = {
|
||||
queryOptions<Map<PayeeEntity['id'], number>>({
|
||||
queryKey: [...payeeQueries.lists(), 'ruleCounts'],
|
||||
queryFn: async () => {
|
||||
const counts = await send('payees-get-rule-counts');
|
||||
const counts = await server.getPayeeRuleCounts();
|
||||
return new Map(Object.entries(counts ?? {}));
|
||||
},
|
||||
placeholderData: new Map(),
|
||||
|
||||
Reference in New Issue
Block a user