diff --git a/src/api/lab/index.ts b/src/api/lab/index.ts index cc35aab5..ab2de217 100644 --- a/src/api/lab/index.ts +++ b/src/api/lab/index.ts @@ -7,9 +7,9 @@ import { } from '~/types/lab'; import { api, cleanResult } from '~/utils/api'; -export const getLabNodes = ({ after, sort }: GetLabNodesRequest) => +export const getLabNodes = ({ offset, limit, sort }: GetLabNodesRequest) => api - .get(API.LAB.NODES, { params: { after, sort } }) + .get(API.LAB.NODES, { params: { offset, limit, sort } }) .then(cleanResult); export const getLabStats = () => api.get(API.LAB.STATS).then(cleanResult); diff --git a/src/hooks/lab/useGetLabNodes.ts b/src/hooks/lab/useGetLabNodes.ts index 21a02b7f..64c86b5b 100644 --- a/src/hooks/lab/useGetLabNodes.ts +++ b/src/hooks/lab/useGetLabNodes.ts @@ -7,22 +7,18 @@ import { useAuth } from '~/hooks/auth/useAuth'; import { useLabStore } from '~/store/lab/useLabStore'; import { INode } from '~/types'; import { GetLabNodesRequest, ILabNode, LabNodesSort } from '~/types/lab'; -import { flatten, last, uniqBy } from '~/utils/ramda'; +import { flatten, uniqBy } from '~/utils/ramda'; const getKey: (isUser: boolean, sort?: LabNodesSort) => SWRInfiniteKeyLoader = (isUser, sort) => ( index, prev: ILabNode[] ) => { if (!isUser) return null; - if (index > 0 && !prev?.length) return null; - - const lastNode = last(prev || []); - if (!lastNode && index > 0) { - return null; - } + if (index > 0 && (!prev?.length || prev.length < 20)) return null; const props: GetLabNodesRequest = { - after: lastNode?.node.commented_at || lastNode?.node.created_at, + limit: 20, + offset: index * 20, sort: sort || LabNodesSort.New, }; diff --git a/src/types/lab/index.ts b/src/types/lab/index.ts index e1860ba8..8dd7127d 100644 --- a/src/types/lab/index.ts +++ b/src/types/lab/index.ts @@ -25,6 +25,8 @@ export enum LabNodesSort { } export type GetLabNodesRequest = { + limit?: number; + offset?: number; after?: string; sort?: LabNodesSort; };