Skip to content

Commit b671461

Browse files
fix: revert bad merge "feature: add orderBy for workerpools and apps (#94)"
1 parent ed0986f commit b671461

File tree

12 files changed

+52
-297
lines changed

12 files changed

+52
-297
lines changed

src/components/PaginatedNavigation.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,20 @@ type PaginationControlsProps = {
1414
currentPage: number;
1515
totalPages: number;
1616
onPageChange: (page: number) => void;
17-
// Optional key whose change can shrink/grow pages immediately (e.g. active filter)
18-
filterKey?: string;
1917
};
2018

2119
export const PaginatedNavigation = ({
2220
currentPage,
2321
totalPages,
2422
onPageChange,
25-
filterKey,
2623
}: PaginationControlsProps) => {
2724
const { chainId } = useUserStore();
2825

2926
const lastValidTotalPagesRef = useRef(1);
3027
const lastChainIdRef = useRef<number | null>(null);
3128
const chainChangeFrameRef = useRef(0);
3229

33-
const lastFilterKeyRef = useRef<string | undefined>(undefined);
34-
const filterChangeFrameRef = useRef(0);
35-
3630
const chainHasChanged = chainId !== lastChainIdRef.current;
37-
const filterHasChanged = filterKey !== lastFilterKeyRef.current;
3831

3932
if (chainHasChanged) {
4033
lastChainIdRef.current = chainId ?? null;
@@ -43,72 +36,66 @@ export const PaginatedNavigation = ({
4336
chainChangeFrameRef.current++;
4437
}
4538

46-
if (filterHasChanged) {
47-
lastFilterKeyRef.current = filterKey;
48-
filterChangeFrameRef.current = 0;
49-
} else {
50-
filterChangeFrameRef.current++;
51-
}
52-
5339
let stableTotalPages = lastValidTotalPagesRef.current;
5440

5541
const isRecentChainChange = chainChangeFrameRef.current <= 5;
56-
const isRecentFilterChange = filterChangeFrameRef.current <= 5;
57-
58-
if (
59-
chainHasChanged ||
60-
filterHasChanged ||
61-
isRecentChainChange ||
62-
isRecentFilterChange
63-
) {
42+
43+
if (chainHasChanged || isRecentChainChange) {
6444
stableTotalPages = Math.max(totalPages, 1);
6545
} else if (totalPages > 0 && totalPages >= lastValidTotalPagesRef.current) {
6646
stableTotalPages = totalPages;
6747
}
68-
// Reset page if it no longer exists after filter change
69-
if (filterHasChanged && currentPage > stableTotalPages) {
70-
onPageChange(1);
71-
}
7248

7349
lastValidTotalPagesRef.current = stableTotalPages;
7450

51+
// Don't render pagination if no pages or invalid state
7552
if (!stableTotalPages || stableTotalPages <= 0 || currentPage <= 0) {
7653
return null;
7754
}
7855

7956
const generatePages = () => {
8057
const pages: (number | 'ellipsis')[] = [];
8158

59+
// Mobile-first approach: show fewer pages on small screens
8260
const isMobile = typeof window !== 'undefined' && window.innerWidth < 640;
8361
const maxVisiblePages = isMobile ? 3 : 7;
8462

8563
if (stableTotalPages <= maxVisiblePages) {
64+
// Show all pages if within limit
8665
for (let i = 1; i <= stableTotalPages; i++) {
8766
pages.push(i);
8867
}
8968
} else if (isMobile) {
69+
// Mobile: simplified pagination - only show current and neighbors
9070
if (currentPage === 1) {
71+
// At start: 1 2 ... last
9172
pages.push(1, 2, 'ellipsis', stableTotalPages);
9273
} else if (currentPage === stableTotalPages) {
74+
// At end: 1 ... (last-1) last
9375
pages.push(1, 'ellipsis', stableTotalPages - 1, stableTotalPages);
9476
} else {
77+
// Middle: 1 ... current ... last
9578
pages.push(1, 'ellipsis', currentPage, 'ellipsis', stableTotalPages);
9679
}
9780
} else {
81+
// Desktop: full pagination logic
9882
pages.push(1);
9983

10084
if (currentPage <= 3) {
85+
// Near beginning: 1 2 3 4 ... last
10186
for (let i = 2; i <= 4; i++) {
10287
pages.push(i);
10388
}
10489
pages.push('ellipsis');
10590
pages.push(stableTotalPages);
10691
} else if (currentPage >= stableTotalPages - 2) {
92+
// Near end: 1 ... (last-3) (last-2) (last-1) last
10793
pages.push('ellipsis');
10894
for (let i = stableTotalPages - 3; i <= stableTotalPages; i++) {
10995
pages.push(i);
11096
}
11197
} else {
98+
// In middle: 1 ... (current-1) current (current+1) ... last
11299
pages.push('ellipsis');
113100
for (let i = currentPage - 1; i <= currentPage + 1; i++) {
114101
pages.push(i);

src/components/ui/select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function SelectTrigger({
4141
>
4242
{children}
4343
<SelectPrimitive.Icon asChild>
44-
<ChevronDownIcon className="text-foreground size-4" />
44+
<ChevronDownIcon className="size-4" />
4545
</SelectPrimitive.Icon>
4646
</SelectPrimitive.Trigger>
4747
);

src/hooks/useFilterParam.ts

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

src/modules/apps/AppsPreviewTable.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PREVIEW_TABLE_LENGTH, PREVIEW_TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/poco/execute';
3-
import { App_OrderBy, OrderDirection } from '@/graphql/poco/graphql';
43
import { cn } from '@/lib/utils';
54
import { useQuery } from '@tanstack/react-query';
65
import { LoaderCircle } from 'lucide-react';
@@ -9,39 +8,25 @@ import { DataTable } from '@/components/DataTable';
98
import AppIcon from '@/components/icons/AppIcon';
109
import { Button } from '@/components/ui/button';
1110
import useUserStore from '@/stores/useUser.store';
12-
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
13-
import { getRecentFromTimestamp } from '@/utils/format';
11+
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
1412
import { ErrorAlert } from '../ErrorAlert';
1513
import { appsQuery } from './appsQuery';
1614
import { columns } from './appsTable/columns';
1715

1816
export function AppsPreviewTable({ className }: { className?: string }) {
1917
const { chainId } = useUserStore();
2018

21-
// Pertinent ordering: usageCount desc + recent usage constraint (last 14 days)
22-
const recentFrom = getRecentFromTimestamp();
23-
const orderBy: App_OrderBy = App_OrderBy.UsageCount;
24-
const orderDirection: OrderDirection = OrderDirection.Desc;
25-
const queryKey = [
26-
chainId,
27-
'apps_preview',
28-
orderBy,
29-
orderDirection,
30-
recentFrom,
31-
];
19+
const queryKey = [chainId, 'apps_preview'];
3220
const apps = useQuery({
3321
queryKey,
3422
queryFn: () =>
3523
execute(appsQuery, chainId, {
3624
length: PREVIEW_TABLE_LENGTH,
3725
skip: 0,
38-
orderBy,
39-
orderDirection,
40-
recentFrom,
4126
}),
4227
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
4328
enabled: !!chainId,
44-
placeholderData: createPlaceholderDataFn(),
29+
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
4530
});
4631

4732
const formattedData =
@@ -55,7 +40,7 @@ export function AppsPreviewTable({ className }: { className?: string }) {
5540
<div className="flex items-center justify-between">
5641
<h2 className="flex items-center gap-2 font-sans">
5742
<AppIcon size={20} className="text-foreground" />
58-
Most pertinent apps
43+
Latest apps deployed
5944
{apps.data && apps.isError && (
6045
<span className="text-muted-foreground text-sm font-light">
6146
(outdated)

src/modules/apps/appsQuery.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ export const appsQuery = graphql(`
66
$skip: Int = 0
77
$nextSkip: Int = 20
88
$nextNextSkip: Int = 40
9-
$orderBy: App_orderBy = timestamp
10-
$orderDirection: OrderDirection = desc
11-
$recentFrom: BigInt = 0
129
) {
1310
apps(
1411
first: $length
1512
skip: $skip
16-
where: { lastUsageTimestamp_gte: $recentFrom }
17-
orderBy: $orderBy
18-
orderDirection: $orderDirection
13+
orderBy: timestamp
14+
orderDirection: desc
1915
) {
2016
address: id
2117
owner {
@@ -27,7 +23,6 @@ export const appsQuery = graphql(`
2723
multiaddr
2824
checksum
2925
mrenclave
30-
lastUsageTimestamp
3126
transfers(orderBy: timestamp, orderDirection: desc) {
3227
transaction {
3328
txHash: id
@@ -39,18 +34,16 @@ export const appsQuery = graphql(`
3934
appsHasNext: apps(
4035
first: 1
4136
skip: $nextSkip
42-
orderBy: $orderBy
43-
orderDirection: $orderDirection
44-
where: { lastUsageTimestamp_gte: $recentFrom }
37+
orderBy: timestamp
38+
orderDirection: desc
4539
) {
4640
address: id
4741
}
4842
appsHasNextNext: apps(
4943
first: 1
5044
skip: $nextNextSkip
51-
orderBy: $orderBy
52-
orderDirection: $orderDirection
53-
where: { lastUsageTimestamp_gte: $recentFrom }
45+
orderBy: timestamp
46+
orderDirection: desc
5447
) {
5548
address: id
5649
}

src/modules/search/SearcherBar.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,8 @@ export function SearcherBar({
174174
/>
175175
</div>
176176

177-
<div
178-
className={cn(
179-
'mt-4 flex justify-center gap-4 sm:hidden',
180-
isError && 'mt-10'
181-
)}
182-
>
183-
<div className="flex justify-center">
177+
<div className={cn('mt-4 flex justify-center gap-4', isError && 'mt-10')}>
178+
<div className="flex justify-center sm:hidden">
184179
<Button variant="outline" onClick={handleSearch} disabled={isPending}>
185180
{isPending ? 'Searching...' : 'Search'}
186181
</Button>

src/modules/workerpools/WorkerpoolsPreviewTable.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PREVIEW_TABLE_LENGTH, PREVIEW_TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/poco/execute';
3-
import { Workerpool_OrderBy, OrderDirection } from '@/graphql/poco/graphql';
43
import { cn } from '@/lib/utils';
54
import { useQuery } from '@tanstack/react-query';
65
import { LoaderCircle } from 'lucide-react';
@@ -9,39 +8,25 @@ import { DataTable } from '@/components/DataTable';
98
import WorkerpoolIcon from '@/components/icons/WorkerpoolIcon';
109
import { Button } from '@/components/ui/button';
1110
import useUserStore from '@/stores/useUser.store';
12-
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
13-
import { getRecentFromTimestamp } from '@/utils/format';
11+
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
1412
import { ErrorAlert } from '../ErrorAlert';
1513
import { workerpoolsQuery } from './workerpoolsQuery';
1614
import { columns } from './workerpoolsTable/columns';
1715

1816
export function WorkerpoolsPreviewTable({ className }: { className?: string }) {
1917
const { chainId } = useUserStore();
2018

21-
// Pertinent ordering: usageCount desc + recent usage constraint (last 14 days)
22-
const recentFrom = getRecentFromTimestamp();
23-
const orderBy: Workerpool_OrderBy = Workerpool_OrderBy.UsageCount;
24-
const orderDirection: OrderDirection = OrderDirection.Desc;
25-
const queryKey = [
26-
chainId,
27-
'workerpools_preview',
28-
orderBy,
29-
orderDirection,
30-
recentFrom,
31-
];
19+
const queryKey = [chainId, 'workerpools_preview'];
3220
const workerpools = useQuery({
3321
queryKey,
3422
queryFn: () =>
3523
execute(workerpoolsQuery, chainId, {
3624
length: PREVIEW_TABLE_LENGTH,
3725
skip: 0,
38-
orderBy,
39-
orderDirection,
40-
recentFrom,
4126
}),
4227
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
4328
enabled: !!chainId,
44-
placeholderData: createPlaceholderDataFn(),
29+
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
4530
});
4631

4732
const formattedData =
@@ -55,7 +40,7 @@ export function WorkerpoolsPreviewTable({ className }: { className?: string }) {
5540
<div className="flex items-center justify-between">
5641
<h2 className="flex items-center gap-2 font-sans">
5742
<WorkerpoolIcon size={20} className="text-foreground" />
58-
Most pertinent workerpools
43+
Latest workerpools deployed
5944
{workerpools.data && workerpools.isError && (
6045
<span className="text-muted-foreground text-sm font-light">
6146
(outdated)

0 commit comments

Comments
 (0)