Skip to content

Commit 92c01a3

Browse files
feat: subgraphs request number optimization (#38)
* fix: update favicon to use new logo and remove unused vite.svg * fix: improve validation logic in DownloadResult component * feat: enhance SmartLinkGroup with ENS lookup and display * fix: simplify no dataset message in deals table * feat: display dataset name in deal details * fix: remove WalletConnect integration from wagmiConfig using default reown instead * feat: add splat route for dynamic handling in chain slug layout * feat: replace dataset and workerpool name display with CopyButton for easier copying * feat: reorder columns; update formatElapsedTime to return 'just now' instead of 'a few second ago' * refactor: replace inline styles with class-based color management in SuccessCell component * fix: update Tabs component layout for better responsiveness * feat: enhance CopyButton to display tooltip with text in various components and fix overflow * fix: correct type for SmartLinkGroup in transaction details * feat: add MrEnclave display in app details and implement mrEnclaveHexToHuman utility * fix: testing corrected Buffer not found * fix: standardize string method usage in mrEnclaveHexToHuman function * feat: add buffer dependency and import in format utility functions * fix: implement address contribution columns and update data handling in AddressContributionTable * fix: enhance big time formatting in formatElapsedTime function * feat: add custom scrollbar styles for improved UI experience * fix: improve formatting consistency in formatElapsedTime function * fix: remove unused finalDeadlineTimestamp from StatusCell * fix: simplify StatusCell rendering in columns definition * fix: update layout and styling for improved responsiveness and consistency * feat: replace default box icon by page data corresponding icon * fix: bad icon case in import * docs: update README with project description, features, installation instructions, and tech stack * feat: implement address and id validation functions, enhance error handling with NotFoundError class * feat: enable scroll restoration in router initialization for improved navigation experience * fix: update table body styles for improved zebra striping and hover effects * feat: enhance CopyButton component for mobile compatibility to avoid miss click * fix: adjust layout widths and table column spans for improved responsiveness * refactor: streamline CopyButton component layout and improve mobile interaction * feat: add breadcrumb components for apps, datasets, deals, tasks, and workerpools to enhance navigation * feat: update preview tables to include specific labels for apps, datasets, deals, tasks, and workerpools for improved clarity * feat: update layout to utilize new 3xl breakpoint for improved responsiveness of preview tables * fix: adjust spacing in DatasetsPreviewTable and WorkerpoolsPreviewTable for improved readability * style: update button and anchor styles to ensure consistent cursor behavior * style: change pagination button size from default to icon for improved visual consistency * style: update Root component layout for improved structure and spacing * fix: prevent rendering of MrEnclave block when value is '0x' to ensure accurate display of app details * fix: a <button> cannot be nested inside another <button> * feat: enhance pagination fetch by combining query * feat: enhance pagination fetch by combining query * style: format GraphQL queries for improved readability by aligning parameters * feat: implement usePageParam hook for consistent pagination state management and url page preservation * refactor: replace manual pagination logic with getAdditionalPages utility for cleaner code and improved maintainability
1 parent ec77b26 commit 92c01a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+689
-679
lines changed

src/hooks/usePageParam.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useSearch, useNavigate } from '@tanstack/react-router';
2+
3+
export function usePageParam(paramName: string, defaultValue = 1) {
4+
const search = useSearch({ strict: false });
5+
const navigate = useNavigate();
6+
7+
const page = Number(search?.[paramName]) || defaultValue;
8+
9+
const setPage = (newPage: number) => {
10+
if (newPage !== page) {
11+
navigate({
12+
search: (prev) => ({
13+
...prev,
14+
[paramName]: newPage,
15+
}),
16+
replace: true,
17+
resetScroll: false,
18+
});
19+
}
20+
};
21+
22+
return [page, setPage] as const;
23+
}

src/modules/addresses/address/apps/AddressAppsTable.tsx

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { PREVIEW_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/execute';
33
import { useQuery } from '@tanstack/react-query';
44
import { LoaderCircle } from 'lucide-react';
5-
import { useState } from 'react';
65
import { DataTable } from '@/components/DataTable';
76
import { PaginatedNavigation } from '@/components/PaginatedNavigation';
7+
import { usePageParam } from '@/hooks/usePageParam';
88
import { ErrorAlert } from '@/modules/ErrorAlert';
99
import { columns } from '@/modules/apps/appsTable/columns';
1010
import useUserStore from '@/stores/useUser.store';
1111
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
12+
import { getAdditionalPages } from '@/utils/format';
1213
import { addressAppsQuery } from './addressAppsQuery';
13-
import { nextAddressAppsQuery } from './nextAddressAppsQuery';
1414

1515
function useAddressAppsData({
1616
addressAddress,
@@ -21,6 +21,8 @@ function useAddressAppsData({
2121
}) {
2222
const { chainId } = useUserStore();
2323
const skip = currentPage * PREVIEW_TABLE_LENGTH;
24+
const nextSkip = skip + PREVIEW_TABLE_LENGTH;
25+
const nextNextSkip = skip + 2 * PREVIEW_TABLE_LENGTH;
2426

2527
const queryKey = [chainId, 'address', 'apps', addressAddress, currentPage];
2628
const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery(
@@ -30,44 +32,30 @@ function useAddressAppsData({
3032
execute(addressAppsQuery, chainId, {
3133
length: PREVIEW_TABLE_LENGTH,
3234
skip,
35+
nextSkip,
36+
nextNextSkip,
3337
address: addressAddress,
3438
}),
3539
refetchInterval: TABLE_REFETCH_INTERVAL,
3640
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
3741
}
3842
);
3943

40-
const queryKeyNextData = [
41-
chainId,
42-
'address',
43-
'apps-next',
44-
addressAddress,
45-
currentPage,
46-
];
47-
const { data: nextData } = useQuery({
48-
queryKey: queryKeyNextData,
49-
queryFn: () =>
50-
execute(nextAddressAppsQuery, chainId, {
51-
length: PREVIEW_TABLE_LENGTH * 2,
52-
skip: (currentPage + 1) * PREVIEW_TABLE_LENGTH,
53-
address: addressAddress,
54-
}),
55-
refetchInterval: TABLE_REFETCH_INTERVAL,
56-
placeholderData: createPlaceholderDataFnForQueryKey(queryKeyNextData),
57-
});
58-
59-
const nextApps = nextData?.account?.apps ?? [];
60-
61-
const additionalPages = Math.ceil(nextApps.length / PREVIEW_TABLE_LENGTH);
44+
const apps = data?.account?.apps ?? [];
45+
// 0 = only current, 1 = next, 2 = next+1
46+
const additionalPages = getAdditionalPages(
47+
Boolean(data?.account?.appsHasNext?.length),
48+
Boolean(data?.account?.appsHasNextNext?.length)
49+
);
6250

63-
const formattedDeal =
64-
data?.account?.apps.map((app) => ({
51+
const formattedApps =
52+
apps.map((app) => ({
6553
...app,
6654
destination: `/app/${app.address}`,
6755
})) ?? [];
6856

6957
return {
70-
data: formattedDeal,
58+
data: formattedApps,
7159
isLoading,
7260
isRefetching,
7361
isError,
@@ -81,15 +69,15 @@ export function AddressAppsTable({
8169
}: {
8270
addressAddress: string;
8371
}) {
84-
const [currentPage, setCurrentPage] = useState(0);
72+
const [currentPage, setCurrentPage] = usePageParam('addressAppsPage');
8573
const {
8674
data: apps,
8775
isError,
8876
isLoading,
8977
isRefetching,
9078
additionalPages,
9179
hasPastError,
92-
} = useAddressAppsData({ addressAddress, currentPage });
80+
} = useAddressAppsData({ addressAddress, currentPage: currentPage - 1 });
9381

9482
const filteredColumns = columns.filter(
9583
(col) => col.accessorKey !== 'owner.address'
@@ -118,9 +106,9 @@ export function AddressAppsTable({
118106
/>
119107
)}
120108
<PaginatedNavigation
121-
currentPage={currentPage + 1}
122-
totalPages={currentPage + 1 + additionalPages}
123-
onPageChange={(newPage) => setCurrentPage(newPage - 1)}
109+
currentPage={currentPage}
110+
totalPages={currentPage + additionalPages}
111+
onPageChange={setCurrentPage}
124112
/>
125113
</div>
126114
);

src/modules/addresses/address/apps/addressAppsQuery.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { graphql } from '@/graphql/gql';
22

33
export const addressAppsQuery = graphql(`
4-
query AddressApps($length: Int = 20, $skip: Int = 0, $address: ID!) {
4+
query AddressApps(
5+
$length: Int = 20
6+
$skip: Int = 0
7+
$nextSkip: Int = 20
8+
$nextNextSkip: Int = 40
9+
$address: ID!
10+
) {
511
account(id: $address) {
612
address: id
713
# apps
@@ -20,6 +26,22 @@ export const addressAppsQuery = graphql(`
2026
}
2127
}
2228
}
29+
appsHasNext: apps(
30+
orderBy: timestamp
31+
orderDirection: desc
32+
first: 1
33+
skip: $nextSkip
34+
) {
35+
address: id
36+
}
37+
appsHasNextNext: apps(
38+
orderBy: timestamp
39+
orderDirection: desc
40+
first: 1
41+
skip: $nextNextSkip
42+
) {
43+
address: id
44+
}
2345
}
2446
}
2547
`);

src/modules/addresses/address/apps/nextAddressAppsQuery.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/modules/addresses/address/datasets/AddressDatasetsTable.tsx

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { PREVIEW_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/execute';
33
import { useQuery } from '@tanstack/react-query';
44
import { LoaderCircle } from 'lucide-react';
5-
import { useState } from 'react';
65
import { DataTable } from '@/components/DataTable';
76
import { PaginatedNavigation } from '@/components/PaginatedNavigation';
7+
import { usePageParam } from '@/hooks/usePageParam';
88
import { ErrorAlert } from '@/modules/ErrorAlert';
99
import { columns } from '@/modules/datasets/datasetsTable/columns';
1010
import useUserStore from '@/stores/useUser.store';
1111
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
12+
import { getAdditionalPages } from '@/utils/format';
1213
import { addressDatasetsQuery } from './addressDatasetsQuery';
13-
import { nextAddressDatasetsQuery } from './nextAddressDatasetsQuery';
1414

1515
function useAddressDatasetsData({
1616
addressAddress,
@@ -21,6 +21,8 @@ function useAddressDatasetsData({
2121
}) {
2222
const { chainId } = useUserStore();
2323
const skip = currentPage * PREVIEW_TABLE_LENGTH;
24+
const nextSkip = skip + PREVIEW_TABLE_LENGTH;
25+
const nextNextSkip = skip + 2 * PREVIEW_TABLE_LENGTH;
2426

2527
const queryKey = [
2628
chainId,
@@ -36,44 +38,30 @@ function useAddressDatasetsData({
3638
execute(addressDatasetsQuery, chainId, {
3739
length: PREVIEW_TABLE_LENGTH,
3840
skip,
41+
nextSkip,
42+
nextNextSkip,
3943
address: addressAddress,
4044
}),
4145
refetchInterval: TABLE_REFETCH_INTERVAL,
4246
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
4347
}
4448
);
4549

46-
const queryKeyNextData = [
47-
chainId,
48-
'address',
49-
'datasets',
50-
addressAddress,
51-
currentPage,
52-
];
53-
const { data: nextData } = useQuery({
54-
queryKey: queryKeyNextData,
55-
queryFn: () =>
56-
execute(nextAddressDatasetsQuery, chainId, {
57-
length: PREVIEW_TABLE_LENGTH * 2,
58-
skip: (currentPage + 1) * PREVIEW_TABLE_LENGTH,
59-
address: addressAddress,
60-
}),
61-
refetchInterval: TABLE_REFETCH_INTERVAL,
62-
placeholderData: createPlaceholderDataFnForQueryKey(queryKeyNextData),
63-
});
64-
65-
const nextDatasets = nextData?.account?.datasets ?? [];
66-
67-
const additionalPages = Math.ceil(nextDatasets.length / PREVIEW_TABLE_LENGTH);
50+
const datasets = data?.account?.datasets ?? [];
51+
// 0 = only current, 1 = next, 2 = next+1
52+
const additionalPages = getAdditionalPages(
53+
Boolean(data?.account?.datasetsHasNext?.length),
54+
Boolean(data?.account?.datasetsHasNextNext?.length)
55+
);
6856

69-
const formattedDeal =
70-
data?.account?.datasets.map((dataset) => ({
57+
const datasetsDatasets =
58+
datasets.map((dataset) => ({
7159
...dataset,
7260
destination: `/dataset/${dataset.address}`,
7361
})) ?? [];
7462

7563
return {
76-
data: formattedDeal,
64+
data: datasetsDatasets,
7765
isLoading,
7866
isRefetching,
7967
isError,
@@ -87,15 +75,15 @@ export function AddressDatasetsTable({
8775
}: {
8876
addressAddress: string;
8977
}) {
90-
const [currentPage, setCurrentPage] = useState(0);
78+
const [currentPage, setCurrentPage] = usePageParam('addressDatasetsPage');
9179
const {
9280
data: datasets,
9381
isError,
9482
isLoading,
9583
isRefetching,
9684
additionalPages,
9785
hasPastError,
98-
} = useAddressDatasetsData({ addressAddress, currentPage });
86+
} = useAddressDatasetsData({ addressAddress, currentPage: currentPage - 1 });
9987

10088
const filteredColumns = columns.filter(
10189
(col) => col.accessorKey !== 'owner.address'
@@ -124,9 +112,9 @@ export function AddressDatasetsTable({
124112
/>
125113
)}
126114
<PaginatedNavigation
127-
currentPage={currentPage + 1}
128-
totalPages={currentPage + 1 + additionalPages}
129-
onPageChange={(newPage) => setCurrentPage(newPage - 1)}
115+
currentPage={currentPage}
116+
totalPages={currentPage + additionalPages}
117+
onPageChange={setCurrentPage}
130118
/>
131119
</div>
132120
);

src/modules/addresses/address/datasets/addressDatasetsQuery.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { graphql } from '@/graphql/gql';
22

33
export const addressDatasetsQuery = graphql(`
4-
query AddressDatasets($length: Int = 20, $skip: Int = 0, $address: ID!) {
4+
query AddressDatasets(
5+
$length: Int = 20
6+
$skip: Int = 0
7+
$nextSkip: Int = 20
8+
$nextNextSkip: Int = 40
9+
$address: ID!
10+
) {
511
account(id: $address) {
612
address: id
713
# datasets
@@ -20,6 +26,22 @@ export const addressDatasetsQuery = graphql(`
2026
}
2127
}
2228
}
29+
datasetsHasNext: datasets(
30+
orderBy: timestamp
31+
orderDirection: desc
32+
first: 1
33+
skip: $nextSkip
34+
) {
35+
address: id
36+
}
37+
datasetsHasNextNext: datasets(
38+
orderBy: timestamp
39+
orderDirection: desc
40+
first: 1
41+
skip: $nextNextSkip
42+
) {
43+
address: id
44+
}
2345
}
2446
}
2547
`);

src/modules/addresses/address/datasets/nextAddressDatasetsQuery.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)