Skip to content

Commit de4929f

Browse files
committed
fix: call react hook after return
1 parent 96865e2 commit de4929f

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,6 @@ function DealsRoute() {
7373
error,
7474
} = useDealData((dealId as string).toLowerCase(), chainId!);
7575

76-
const [isLoadingChild, setIsLoadingChild] = useState(false);
77-
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
78-
79-
const dealDetails = deal
80-
? buildDealDetails({
81-
deal,
82-
isConnected,
83-
onSeeTasks: () => setCurrentTab(1),
84-
})
85-
: undefined;
86-
87-
if (!isValid) {
88-
return <ErrorAlert className="my-16" message="Invalid deal address." />;
89-
}
90-
91-
if (isError && error instanceof NotFoundError) {
92-
return <ErrorAlert className="my-16" message="Deal not found." />;
93-
}
94-
9576
const associatedDealsPresenceQueryKey = [
9677
chainId,
9778
'deal',
@@ -100,7 +81,7 @@ function DealsRoute() {
10081
];
10182
const { data: associatedDealsPresence } = useQuery({
10283
queryKey: associatedDealsPresenceQueryKey,
103-
enabled: dealId && !!chainId && !!deal && currentTab !== 2,
84+
enabled: !!dealId && !!chainId && !!deal && currentTab !== 2,
10485
queryFn: () =>
10586
execute(dealAssociatedDealsQuery, chainId!, {
10687
length: 1,
@@ -114,6 +95,25 @@ function DealsRoute() {
11495
const hasAssociatedDeals =
11596
(associatedDealsPresence?.deal?.requestorder?.deals?.length || 0) > 0;
11697

98+
const [isLoadingChild, setIsLoadingChild] = useState(false);
99+
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
100+
101+
const dealDetails = deal
102+
? buildDealDetails({
103+
deal,
104+
isConnected,
105+
onSeeTasks: () => setCurrentTab(1),
106+
})
107+
: undefined;
108+
109+
if (!isValid) {
110+
return <ErrorAlert className="my-16" message="Invalid deal address." />;
111+
}
112+
113+
if (isError && error instanceof NotFoundError) {
114+
return <ErrorAlert className="my-16" message="Deal not found." />;
115+
}
116+
117117
const showOutdated = deal && (isError || isOutdatedChild);
118118
const showLoading = isLoading || isRefetching || isLoadingChild;
119119

src/routes/$chainSlug/_layout/task/$taskId.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ function TasksRoute() {
7373
const tabLabels = ['DETAILS', 'DATASETS', 'RAW DATA'];
7474
const [currentTab, setCurrentTab] = useTabParam('dealTab', tabLabels, 0);
7575

76-
const [isLoadingChild, setIsLoadingChild] = useState(false);
77-
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
78-
79-
const taskDetails = task ? buildTaskDetails({ task }) : undefined;
80-
81-
if (!isValid) {
82-
return <ErrorAlert className="my-16" message="Invalid task address." />;
83-
}
84-
85-
if (isError && error instanceof NotFoundError) {
86-
return <ErrorAlert message="Task not found." />;
87-
}
88-
89-
// Presence check for datasets to disable tab if none
9076
const datasetsPresenceQueryKey = [
9177
chainId,
9278
'task',
@@ -109,6 +95,19 @@ function TasksRoute() {
10995
const hasDatasets =
11096
(datasetsPresence?.task?.bulkSlice?.datasets?.length || 0) > 0;
11197

98+
const [isLoadingChild, setIsLoadingChild] = useState(false);
99+
const [isOutdatedChild, setIsOutdatedChild] = useState(false);
100+
101+
const taskDetails = task ? buildTaskDetails({ task }) : undefined;
102+
103+
if (!isValid) {
104+
return <ErrorAlert className="my-16" message="Invalid task address." />;
105+
}
106+
107+
if (isError && error instanceof NotFoundError) {
108+
return <ErrorAlert message="Task not found." />;
109+
}
110+
112111
const showOutdated = task && (isError || isOutdatedChild);
113112
const showLoading = isLoading || isRefetching || isLoadingChild;
114113

0 commit comments

Comments
 (0)