Skip to content

Commit 11ef324

Browse files
committed
feat: implement TaskRawData component and integrate with TasksRoute for improved task detail display
1 parent c47dd9a commit 11ef324

File tree

3 files changed

+79
-6
lines changed

3 files changed

+79
-6
lines changed

src/modules/JsonBlock.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ type JsonBlockProps = {
77
className?: string;
88
collapsed?: number;
99
enableClipboard?: boolean;
10+
copyText?: string;
1011
};
1112

1213
const JsonBlock = ({
1314
children,
1415
className,
1516
collapsed = 1,
1617
enableClipboard = true,
18+
copyText = 'Copy',
1719
}: JsonBlockProps) => {
1820
let jsonData: object;
1921
let rawToCopy: string;
@@ -47,10 +49,13 @@ const JsonBlock = ({
4749
displayObjectSize={false}
4850
enableClipboard={false}
4951
collapsed={collapsed}
52+
shortenTextAfterLength={128}
5053
style={defaultJsonViewStyle}
5154
/>
5255
</div>
53-
{enableClipboard && <CopyButton textToCopy={rawToCopy} />}
56+
{enableClipboard && (
57+
<CopyButton buttonText="Copy Json" textToCopy={rawToCopy} />
58+
)}
5459
</div>
5560
);
5661
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { TABLE_REFETCH_INTERVAL } from '@/config';
2+
import { useQuery } from '@tanstack/react-query';
3+
import { ErrorAlert } from '@/modules/ErrorAlert';
4+
import JsonBlock from '@/modules/JsonBlock';
5+
import useUserStore from '@/stores/useUser.store';
6+
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
7+
8+
function useTaskRawData({ taskId }: { taskId: string }) {
9+
const { chainId } = useUserStore();
10+
11+
const queryKey = [chainId, 'task', 'raw', taskId];
12+
const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery(
13+
{
14+
queryKey,
15+
queryFn: async () => {
16+
const response = await fetch(
17+
`https://core-prod.arbitrum-mainnet.iex.ec/tasks/${taskId}`
18+
);
19+
if (!response.ok) {
20+
throw new Error('Failed to fetch task raw data');
21+
}
22+
console.log(response);
23+
24+
return response.json();
25+
},
26+
refetchInterval: TABLE_REFETCH_INTERVAL,
27+
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
28+
}
29+
);
30+
31+
return {
32+
data,
33+
isLoading,
34+
isRefetching,
35+
isError,
36+
hasPastError: isError || errorUpdateCount > 0,
37+
};
38+
}
39+
40+
export function TaskRawData({ taskId }: { taskId: string }) {
41+
const { data: tasks, hasPastError } = useTaskRawData({ taskId });
42+
43+
// TODO: handle loading state
44+
45+
return hasPastError && !tasks.length ? (
46+
<ErrorAlert message="An error occurred during task raw data loading." />
47+
) : (
48+
<div className="dark:bg-tooltip rounded-3xl border bg-[#fafaff] p-6">
49+
<JsonBlock copyText="Copy all" collapsed={5}>
50+
{tasks}
51+
</JsonBlock>
52+
</div>
53+
);
54+
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { createFileRoute } from '@tanstack/react-router';
55
import { LoaderCircle } from 'lucide-react';
66
import TaskIcon from '@/components/icons/TaskIcon';
77
import { BackButton } from '@/components/ui/BackButton';
8+
import { useTabParam } from '@/hooks/usePageParam';
89
import { DetailsTable } from '@/modules/DetailsTable';
910
import { ErrorAlert } from '@/modules/ErrorAlert';
11+
import { Tabs } from '@/modules/Tabs';
1012
import { SearcherBar } from '@/modules/search/SearcherBar';
1113
import { TaskBreadcrumbs } from '@/modules/tasks/task/TaskBreadcrumbs';
14+
import { TaskRawData } from '@/modules/tasks/task/TaskRawData';
1215
import { buildTaskDetails } from '@/modules/tasks/task/buildTaskDetails';
1316
import { taskQuery } from '@/modules/tasks/task/taskQuery';
1417
import useUserStore from '@/stores/useUser.store';
@@ -64,6 +67,8 @@ function TasksRoute() {
6467
isValid,
6568
error,
6669
} = useTaskData((taskId as string).toLowerCase(), chainId!);
70+
const tabLabels = ['DETAILS', 'RAW DATA'];
71+
const [currentTab, setCurrentTab] = useTabParam('dealTab', tabLabels, 0);
6772

6873
const taskDetails = task ? buildTaskDetails({ task }) : undefined;
6974

@@ -99,11 +104,20 @@ function TasksRoute() {
99104
</div>
100105
</div>
101106

102-
{hasPastError && !taskDetails ? (
103-
<ErrorAlert message="An error occurred during task details loading." />
104-
) : (
105-
<DetailsTable details={taskDetails || {}} />
106-
)}
107+
<Tabs
108+
currentTab={currentTab}
109+
tabLabels={tabLabels}
110+
onTabChange={setCurrentTab}
111+
/>
112+
<div>
113+
{currentTab === 0 &&
114+
(hasPastError && !taskDetails ? (
115+
<ErrorAlert message="An error occurred during task details loading." />
116+
) : (
117+
<DetailsTable details={taskDetails || {}} />
118+
))}
119+
{currentTab === 1 && <TaskRawData taskId={taskId} />}
120+
</div>
107121
</div>
108122
);
109123
}

0 commit comments

Comments
 (0)