mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
Apply coderabbit suggestions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// @ts-strict-ignore
|
||||
import { useMemo } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { q } from '../../shared/query';
|
||||
import { type TransactionFilterEntity } from '../../types/models';
|
||||
@@ -25,13 +25,14 @@ export function useFilters(): TransactionFilterEntity[] {
|
||||
[],
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
toJS(data ? [...data] : []).sort((a, b) =>
|
||||
a.name
|
||||
.trim()
|
||||
.localeCompare(b.name.trim(), undefined, { ignorePunctuation: true }),
|
||||
),
|
||||
[data],
|
||||
);
|
||||
/** Sort filters by alphabetical order */
|
||||
const sort = useCallback((filters: TransactionFilterEntity[]) => {
|
||||
return filters.toSorted((a, b) =>
|
||||
a.name
|
||||
.trim()
|
||||
.localeCompare(b.name.trim(), undefined, { ignorePunctuation: true }),
|
||||
);
|
||||
}, []);
|
||||
|
||||
return useMemo(() => sort(toJS(data ? [...data] : [])), [data, sort]);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ function loadStatuses(
|
||||
|
||||
type UseSchedulesProps = {
|
||||
query?: Query;
|
||||
options?: {
|
||||
isDisabled?: boolean;
|
||||
};
|
||||
};
|
||||
type ScheduleData = {
|
||||
schedules: readonly ScheduleEntity[];
|
||||
@@ -60,11 +63,13 @@ type ScheduleData = {
|
||||
};
|
||||
type UseSchedulesResult = ScheduleData & {
|
||||
readonly isLoading: boolean;
|
||||
readonly isDisabled: boolean;
|
||||
readonly error?: Error;
|
||||
};
|
||||
|
||||
export function useSchedules({
|
||||
query,
|
||||
options: { isDisabled } = { isDisabled: false },
|
||||
}: UseSchedulesProps = {}): UseSchedulesResult {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
@@ -98,7 +103,7 @@ export function useSchedules({
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
setIsLoading(query !== null);
|
||||
|
||||
scheduleQueryRef.current = liveQuery<ScheduleEntity>(query, {
|
||||
onData: async schedules => {
|
||||
@@ -126,8 +131,9 @@ export function useSchedules({
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
isDisabled,
|
||||
error,
|
||||
...data,
|
||||
...(isDisabled ? { schedules: [], statuses: new Map() } : data),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -119,13 +119,21 @@ export function useTransactions({
|
||||
};
|
||||
}
|
||||
|
||||
type UsePreviewTransactionsProps = {
|
||||
options?: {
|
||||
isDisabled?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
type UsePreviewTransactionsResult = {
|
||||
data: ReadonlyArray<TransactionEntity>;
|
||||
isLoading: boolean;
|
||||
error?: Error;
|
||||
};
|
||||
|
||||
export function usePreviewTransactions(): UsePreviewTransactionsResult {
|
||||
export function usePreviewTransactions({
|
||||
options: { isDisabled } = { isDisabled: false },
|
||||
}: UsePreviewTransactionsProps = {}): UsePreviewTransactionsResult {
|
||||
const [previewTransactions, setPreviewTransactions] = useState<
|
||||
TransactionEntity[]
|
||||
>([]);
|
||||
@@ -143,6 +151,10 @@ export function usePreviewTransactions(): UsePreviewTransactionsResult {
|
||||
return [];
|
||||
}
|
||||
|
||||
let isUnmounted = false;
|
||||
|
||||
setIsLoading(schedules.length > 0);
|
||||
|
||||
// Kick off an async rules application
|
||||
const schedulesForPreview = schedules.filter(s =>
|
||||
isForPreview(s, statuses),
|
||||
@@ -207,7 +219,7 @@ export function usePreviewTransactions(): UsePreviewTransactionsResult {
|
||||
}, [scheduleTransactions, schedules, statuses]);
|
||||
|
||||
return {
|
||||
data: previewTransactions,
|
||||
data: isDisabled ? [] : previewTransactions,
|
||||
isLoading: isLoading || isSchedulesLoading,
|
||||
error: error || scheduleQueryError,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user