Skip to content

Commit 5451715

Browse files
author
lukaw3d
committed
Fix fragile react queries
1 parent ec317e9 commit 5451715

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

.changelog/377.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix fragile react queries

src/components/AppsList/index.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ export const AppsList: FC<AppsListProps> = ({ emptyState, type }) => {
1919
// Fallback is needed to render Explore page content without wallet connection
2020
const network = useNetwork(type === 'dashboard' ? undefined : 'mainnet')
2121

22-
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
23-
// TODO: missing address param
24-
queryKey: [...getGetRuntimeRoflAppsQueryKey(network, 'sapphire'), type],
25-
queryFn: async ({ pageParam = 0 }) => {
26-
const result = await GetRuntimeRoflApps(network, 'sapphire', {
22+
const appsQueryParams = (pageParam = 0) =>
23+
[
24+
network,
25+
'sapphire',
26+
{
2727
limit: pageLimit,
2828
offset: pageParam,
2929
admin: type === 'dashboard' ? address : undefined,
3030
sort_by: type === 'dashboard' ? 'created_at_desc' : undefined,
31-
})
31+
},
32+
] satisfies Parameters<typeof GetRuntimeRoflApps>
33+
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
34+
queryKey: ['infinite', ...getGetRuntimeRoflAppsQueryKey(...appsQueryParams())],
35+
queryFn: async ({ pageParam = 0 }) => {
36+
const result = await GetRuntimeRoflApps(...appsQueryParams(pageParam))
3237
return result
3338
},
3439
initialPageParam: 0,

src/pages/Dashboard/Machines/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'
55
import { useInView } from 'react-intersection-observer'
66
import { useAccount } from 'wagmi'
77
import { useNetwork } from '../../../hooks/useNetwork'
8-
import { getGetRuntimeRoflAppsQueryKey, GetRuntimeRoflmarketInstances } from '../../../nexus/api'
8+
import { getGetRuntimeRoflmarketInstancesQueryKey, GetRuntimeRoflmarketInstances } from '../../../nexus/api'
99
import { MachineCard } from '../../../components/MachineCard'
1010

1111
const pageLimit = 9
@@ -15,15 +15,20 @@ export const Machines: FC = () => {
1515
const { ref, inView } = useInView()
1616
const network = useNetwork()
1717

18-
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
19-
// TODO: wrong path and missing address param
20-
queryKey: [...getGetRuntimeRoflAppsQueryKey(network, 'sapphire')],
21-
queryFn: async ({ pageParam = 0 }) => {
22-
const result = await GetRuntimeRoflmarketInstances(network, 'sapphire', {
18+
const machinesQueryParams = (pageParam = 0) =>
19+
[
20+
network,
21+
'sapphire',
22+
{
2323
limit: pageLimit,
2424
offset: pageParam,
2525
admin: address,
26-
})
26+
},
27+
] satisfies Parameters<typeof GetRuntimeRoflmarketInstances>
28+
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
29+
queryKey: ['infinite', ...getGetRuntimeRoflmarketInstancesQueryKey(...machinesQueryParams())],
30+
queryFn: async ({ pageParam = 0 }) => {
31+
const result = await GetRuntimeRoflmarketInstances(...machinesQueryParams(pageParam))
2732
return result
2833
},
2934
initialPageParam: 0,

src/pages/Dashboard/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ export const Dashboard: FC = () => {
2727
sort_by: 'created_at_desc',
2828
},
2929
{
30-
// TODO: fragile - will break if we make sort_by customizable
30+
// @ts-expect-error Incorrect type demands queryKey
3131
query: {
32-
queryKey: ['roflAppsPolling', network, address],
3332
refetchInterval: refetchInterval,
3433
},
3534
},
@@ -44,8 +43,8 @@ export const Dashboard: FC = () => {
4443
admin: address,
4544
},
4645
{
46+
// @ts-expect-error Incorrect type demands queryKey
4747
query: {
48-
queryKey: ['roflmachinePolling', network, address],
4948
refetchInterval: refetchInterval,
5049
},
5150
},

0 commit comments

Comments
 (0)