Skip to content

Commit 9a9ac27

Browse files
committed
feat: enhance WorkerpoolDealsTable with loading and outdated state management
1 parent 691c276 commit 9a9ac27

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/modules/workerpools/workerpool/WorkerpoolDealsTable.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ function useWorkerpoolDealsData({
7272

7373
export function WorkerpoolDealsTable({
7474
workerpoolAddress,
75+
setLoading,
76+
setOutdated,
7577
}: {
7678
workerpoolAddress: string;
79+
setLoading: (loading: boolean) => void;
80+
setOutdated: (outdated: boolean) => void;
7781
}) {
7882
const [currentPage, setCurrentPage] = usePageParam('workerpoolDealsPage');
7983
const {
@@ -88,23 +92,15 @@ export function WorkerpoolDealsTable({
8892
currentPage: currentPage - 1,
8993
});
9094

95+
setLoading(isLoading || isRefetching);
96+
setOutdated(deals.length > 0 && isError);
97+
9198
const filteredColumns = columns.filter(
9299
(col) => col.accessorKey !== 'dataset.address'
93100
);
94101

95102
return (
96103
<div className="space-y-6">
97-
<h2 className="flex items-center gap-2 font-extrabold">
98-
Latests deals
99-
{!deals && isError && (
100-
<span className="text-muted-foreground text-sm font-light">
101-
(outdated)
102-
</span>
103-
)}
104-
{(isLoading || isRefetching) && (
105-
<LoaderCircle className="animate-spin" />
106-
)}
107-
</h2>
108104
{hasPastError && !deals.length ? (
109105
<ErrorAlert message="A error occurred during workerpool deals loading." />
110106
) : (

src/routes/$chainSlug/_layout/workerpool/$workerpoolAddress.tsx

Lines changed: 14 additions & 5 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 WorkerpoolIcon from '@/components/icons/WorkerpoolIcon';
78
import { BackButton } from '@/components/ui/BackButton';
89
import { useTabParam } from '@/hooks/usePageParam';
@@ -77,6 +78,9 @@ function WorkerpoolsRoute() {
7778
error,
7879
} = useWorkerpoolData((workerpoolAddress as string).toLowerCase(), chainId!);
7980

81+
const [isLoadingChild, setIsLoadingChild] = useState(false);
82+
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
83+
8084
const workerpoolDetails = workerpool
8185
? buildWorkerpoolDetails({ workerpool })
8286
: undefined;
@@ -91,6 +95,9 @@ function WorkerpoolsRoute() {
9195
return <ErrorAlert className="my-16" message="Workerpool not found." />;
9296
}
9397

98+
const showOutdated = workerpool && (isError || isOutdatedChild);
99+
const showLoading = isLoading || isRefetching || isLoadingChild;
100+
94101
return (
95102
<div className="mt-8 flex flex-col gap-6">
96103
<div className="mt-6 flex flex-col justify-between lg:flex-row">
@@ -99,14 +106,12 @@ function WorkerpoolsRoute() {
99106
<h1 className="flex items-center gap-2 text-2xl font-extrabold">
100107
<WorkerpoolIcon size={24} />
101108
Workerpool details
102-
{workerpool && isError && (
109+
{showOutdated && (
103110
<span className="text-muted-foreground text-sm font-light">
104111
(outdated)
105112
</span>
106113
)}
107-
{(isLoading || isRefetching) && (
108-
<LoaderCircle className="animate-spin" />
109-
)}
114+
{showLoading && <LoaderCircle className="animate-spin" />}
110115
</h1>
111116
<div className="flex items-center gap-2">
112117
<BackButton />
@@ -127,7 +132,11 @@ function WorkerpoolsRoute() {
127132
<DetailsTable details={workerpoolDetails || {}} zebra={false} />
128133
))}
129134
{currentTab === 1 && (
130-
<WorkerpoolDealsTable workerpoolAddress={workerpoolAddress} />
135+
<WorkerpoolDealsTable
136+
workerpoolAddress={workerpoolAddress}
137+
setLoading={setIsLoadingChild}
138+
setOutdated={setIsOutdatedChild}
139+
/>
131140
)}
132141
</div>
133142
);

0 commit comments

Comments
 (0)