mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
fixed offseting in lab by number
This commit is contained in:
parent
26a6d2d919
commit
2f8ce82325
3 changed files with 8 additions and 10 deletions
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue