1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed offseting in lab by number

This commit is contained in:
Fedor Katurov 2022-03-23 18:52:41 +07:00
parent 26a6d2d919
commit 2f8ce82325
3 changed files with 8 additions and 10 deletions

View file

@ -7,9 +7,9 @@ import {
} from '~/types/lab'; } from '~/types/lab';
import { api, cleanResult } from '~/utils/api'; import { api, cleanResult } from '~/utils/api';
export const getLabNodes = ({ after, sort }: GetLabNodesRequest) => export const getLabNodes = ({ offset, limit, sort }: GetLabNodesRequest) =>
api api
.get<GetLabNodesResult>(API.LAB.NODES, { params: { after, sort } }) .get<GetLabNodesResult>(API.LAB.NODES, { params: { offset, limit, sort } })
.then(cleanResult); .then(cleanResult);
export const getLabStats = () => api.get<GetLabStatsResult>(API.LAB.STATS).then(cleanResult); export const getLabStats = () => api.get<GetLabStatsResult>(API.LAB.STATS).then(cleanResult);

View file

@ -7,22 +7,18 @@ import { useAuth } from '~/hooks/auth/useAuth';
import { useLabStore } from '~/store/lab/useLabStore'; import { useLabStore } from '~/store/lab/useLabStore';
import { INode } from '~/types'; import { INode } from '~/types';
import { GetLabNodesRequest, ILabNode, LabNodesSort } from '~/types/lab'; 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) => ( const getKey: (isUser: boolean, sort?: LabNodesSort) => SWRInfiniteKeyLoader = (isUser, sort) => (
index, index,
prev: ILabNode[] prev: ILabNode[]
) => { ) => {
if (!isUser) return null; if (!isUser) return null;
if (index > 0 && !prev?.length) return null; if (index > 0 && (!prev?.length || prev.length < 20)) return null;
const lastNode = last(prev || []);
if (!lastNode && index > 0) {
return null;
}
const props: GetLabNodesRequest = { const props: GetLabNodesRequest = {
after: lastNode?.node.commented_at || lastNode?.node.created_at, limit: 20,
offset: index * 20,
sort: sort || LabNodesSort.New, sort: sort || LabNodesSort.New,
}; };

View file

@ -25,6 +25,8 @@ export enum LabNodesSort {
} }
export type GetLabNodesRequest = { export type GetLabNodesRequest = {
limit?: number;
offset?: number;
after?: string; after?: string;
sort?: LabNodesSort; sort?: LabNodesSort;
}; };