Skip to content

Commit 1f6b6c6

Browse files
committed
feat: enhance DealTasksTable and DealAssociatedDealsTable with loading and outdated state management
1 parent 8c0ec9e commit 1f6b6c6

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

src/modules/deals/deal/DealAssociatedDealsTable.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { columns } from '@/modules/deals/dealsTable/columns';
99
import useUserStore from '@/stores/useUser.store';
1010
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
1111
import { dealAssociatedDealsQuery } from './dealAssociatedDealsQuery';
12+
import { useEffect } from 'react';
1213

1314
function useDealAssociatedDealsData({
1415
dealId,
@@ -56,17 +57,37 @@ function useDealAssociatedDealsData({
5657
};
5758
}
5859

59-
export function DealAssociatedDealsTable({ dealId }: { dealId: string }) {
60+
export function DealAssociatedDealsTable({
61+
dealId,
62+
setLoading,
63+
setOutdated,
64+
}: {
65+
dealId: string;
66+
setLoading: (isLoading: boolean) => void;
67+
setOutdated: (isOutdated: boolean) => void;
68+
}) {
6069
const [currentPage, setCurrentPage] = usePageParam('dealAssociatedDealsPage');
6170
const {
6271
data: associatedDeals,
72+
isError,
73+
isLoading,
74+
isRefetching,
6375
additionalPages,
6476
hasPastError,
6577
} = useDealAssociatedDealsData({
6678
dealId,
6779
currentPage,
6880
});
6981

82+
useEffect(
83+
() => setLoading(isLoading || isRefetching),
84+
[isLoading, isRefetching, setLoading]
85+
);
86+
useEffect(
87+
() => setOutdated(associatedDeals.length > 0 && isError),
88+
[associatedDeals.length, isError, setOutdated]
89+
);
90+
7091
return (
7192
<div className="space-y-6">
7293
{hasPastError && !associatedDeals.length ? (

src/modules/deals/deal/DealTasksTable.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DETAIL_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/poco/execute';
33
import { useQuery } from '@tanstack/react-query';
4+
import { useEffect } from 'react';
45
import { DataTable } from '@/components/DataTable';
56
import { ErrorAlert } from '@/modules/ErrorAlert';
67
import { columns } from '@/modules/tasks/tasksTable/columns';
@@ -40,10 +41,31 @@ function useDealTasksData({ dealId }: { dealId: string }) {
4041
};
4142
}
4243

43-
export function DealTasksTable({ dealId }: { dealId: string }) {
44-
const { data: tasks, hasPastError } = useDealTasksData({ dealId });
44+
export function DealTasksTable({
45+
dealId,
46+
setLoading,
47+
setOutdated,
48+
}: {
49+
dealId: string;
50+
setLoading: (isLoading: boolean) => void;
51+
setOutdated: (isOutdated: boolean) => void;
52+
}) {
53+
const {
54+
data: tasks,
55+
isError,
56+
isLoading,
57+
isRefetching,
58+
hasPastError,
59+
} = useDealTasksData({ dealId });
4560

46-
// TODO: handle loading state
61+
useEffect(
62+
() => setLoading(isLoading || isRefetching),
63+
[isLoading, isRefetching, setLoading]
64+
);
65+
useEffect(
66+
() => setOutdated(tasks.length > 0 && isError),
67+
[tasks.length, isError, setOutdated]
68+
);
4769

4870
const extendedColumns = [
4971
{

src/routes/$chainSlug/_layout/deal/$dealId.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { execute } from '@/graphql/poco/execute';
33
import { useQuery } from '@tanstack/react-query';
44
import { createFileRoute } from '@tanstack/react-router';
55
import { LoaderCircle } from 'lucide-react';
6+
import { useState } from 'react';
67
import DealIcon from '@/components/icons/DealIcon';
78
import { BackButton } from '@/components/ui/BackButton';
89
import { useTabParam } from '@/hooks/usePageParam';
@@ -71,6 +72,9 @@ function DealsRoute() {
7172
error,
7273
} = useDealData((dealId as string).toLowerCase(), chainId!);
7374

75+
const [isLoadingChild, setIsLoadingChild] = useState(false);
76+
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
77+
7478
const dealDetails = deal
7579
? buildDealDetails({
7680
deal,
@@ -87,6 +91,9 @@ function DealsRoute() {
8791
return <ErrorAlert className="my-16" message="Deal not found." />;
8892
}
8993

94+
const showOutdated = deal && (isError || isOutdatedChild);
95+
const showLoading = isLoading || isRefetching || isLoadingChild;
96+
9097
return (
9198
<div className="mt-8 flex flex-col gap-6">
9299
<div className="mt-6 flex flex-col justify-between lg:flex-row">
@@ -95,14 +102,12 @@ function DealsRoute() {
95102
<h1 className="flex items-center gap-2 font-sans text-2xl font-extrabold">
96103
<DealIcon size={24} />
97104
Deal details
98-
{!deal && isError && (
105+
{showOutdated && (
99106
<span className="text-muted-foreground text-sm font-light">
100107
(outdated)
101108
</span>
102109
)}
103-
{(isLoading || isRefetching) && (
104-
<LoaderCircle className="animate-spin" />
105-
)}
110+
{showLoading && <LoaderCircle className="animate-spin" />}
106111
</h1>
107112
<div className="flex items-center gap-2">
108113
<BackButton />
@@ -123,8 +128,20 @@ function DealsRoute() {
123128
) : (
124129
<DetailsTable details={dealDetails || {}} />
125130
))}
126-
{currentTab === 1 && <DealTasksTable dealId={dealId} />}
127-
{currentTab === 2 && <DealAssociatedDealsTable dealId={dealId} />}
131+
{currentTab === 1 && (
132+
<DealTasksTable
133+
dealId={dealId}
134+
setLoading={setIsLoadingChild}
135+
setOutdated={setIsOutdatedChild}
136+
/>
137+
)}
138+
{currentTab === 2 && (
139+
<DealAssociatedDealsTable
140+
dealId={dealId}
141+
setLoading={setIsLoadingChild}
142+
setOutdated={setIsOutdatedChild}
143+
/>
144+
)}
128145
</div>
129146
</div>
130147
);

0 commit comments

Comments
 (0)