11import { useEffect , type FC , type ReactNode } from 'react'
22import { Skeleton } from '@oasisprotocol/ui-library/src/components/ui/skeleton'
33import { AppCard } from '../AppCard'
4- import { getGetRuntimeRoflAppsQueryKey , GetRuntimeRoflApps } from '../../nexus/api'
4+ import { GetRuntimeRoflApps } from '../../nexus/api'
55import { useNetwork } from '../../hooks/useNetwork'
6- import { useInfiniteQuery } from '@tanstack/react-query'
76import { useInView } from 'react-intersection-observer'
87import { useAccount } from 'wagmi'
8+ import { useNexusInfiniteQuery } from '../../utils/useNexusInfiniteQuery'
99
1010type AppsListProps = {
1111 emptyState : ReactNode
@@ -19,30 +19,22 @@ 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 appsQueryParams = ( pageParam = 0 ) =>
23- [
24- network ,
25- 'sapphire' ,
26- {
27- limit : pageLimit ,
28- offset : pageParam ,
29- admin : type === 'dashboard' ? address : undefined ,
30- sort_by : type === 'dashboard' ? 'created_at_desc' : undefined ,
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 ) )
37- return result
38- } ,
39- initialPageParam : 0 ,
40- enabled : type === 'explore' || ( type === 'dashboard' && isConnected ) ,
41- getNextPageParam : ( lastPage , allPages ) => {
42- const totalFetched = allPages . length * pageLimit
43- return lastPage . data . rofl_apps . length < lastPage . data . total_count ? totalFetched : undefined
44- } ,
45- } )
22+ const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } =
23+ useNexusInfiniteQuery ( {
24+ queryKeyPrefix : 'rofl_apps' ,
25+ queryFn : GetRuntimeRoflApps ,
26+ resultsField : 'rofl_apps' ,
27+ params : [
28+ network ,
29+ 'sapphire' ,
30+ {
31+ limit : pageLimit ,
32+ admin : type === 'dashboard' ? address : undefined ,
33+ sort_by : type === 'dashboard' ? 'created_at_desc' : undefined ,
34+ } ,
35+ ] ,
36+ enabled : type === 'explore' || ( type === 'dashboard' && isConnected ) ,
37+ } )
4638
4739 useEffect ( ( ) => {
4840 if ( inView && hasNextPage && ! isFetchingNextPage ) {
0 commit comments