mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added lab pagination
This commit is contained in:
parent
ae93ff065d
commit
c986bc434b
8 changed files with 79 additions and 21 deletions
|
@ -34,3 +34,7 @@ export const labSeenNode = (nodeId: INode['id']) => ({
|
|||
type: LAB_ACTIONS.SEEN_NODE,
|
||||
nodeId,
|
||||
});
|
||||
|
||||
export const labGetMore = () => ({
|
||||
type: LAB_ACTIONS.GET_MORE,
|
||||
});
|
||||
|
|
|
@ -10,4 +10,5 @@ export const LAB_ACTIONS = {
|
|||
SET_UPDATES: `${prefix}SET_UPDATES`,
|
||||
GET_UPDATES: `${prefix}GET_UPDATES`,
|
||||
SEEN_NODE: `${prefix}SET_UPDATE_SEEN`,
|
||||
GET_MORE: `${prefix}GET_MORE`,
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
import { LAB_ACTIONS } from '~/redux/lab/constants';
|
||||
import { Unwrap } from '~/redux/types';
|
||||
import { getLabNodes, getLabStats, getLabUpdates } from '~/redux/lab/api';
|
||||
import { selectLabUpdatesNodes } from '~/redux/lab/selectors';
|
||||
import { selectLabList, selectLabUpdatesNodes } from '~/redux/lab/selectors';
|
||||
|
||||
function* getList({ after = '' }: ReturnType<typeof labGetList>) {
|
||||
try {
|
||||
|
@ -53,10 +53,39 @@ function* seenNode({ nodeId }: ReturnType<typeof labSeenNode>) {
|
|||
yield put(labSetUpdates({ nodes: newNodes }));
|
||||
}
|
||||
|
||||
function* getMore() {
|
||||
try {
|
||||
yield put(labSetList({ is_loading: true }));
|
||||
|
||||
const list: ReturnType<typeof selectLabList> = yield select(selectLabList);
|
||||
if (list.nodes.length === list.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const last = list.nodes[list.nodes.length];
|
||||
|
||||
if (!last) {
|
||||
return;
|
||||
}
|
||||
|
||||
const after = last.node.created_at;
|
||||
const { nodes, count }: Unwrap<typeof getLabNodes> = yield call(getLabNodes, { after });
|
||||
const newNodes = [...list.nodes, ...nodes];
|
||||
|
||||
yield put(labSetList({ nodes: newNodes, count }));
|
||||
} catch (error) {
|
||||
yield put(labSetList({ error: error.message }));
|
||||
} finally {
|
||||
yield put(labSetList({ is_loading: false }));
|
||||
}
|
||||
}
|
||||
|
||||
export default function* labSaga() {
|
||||
yield takeLeading(LAB_ACTIONS.GET_LIST, getList);
|
||||
yield takeLeading(LAB_ACTIONS.GET_STATS, getStats);
|
||||
|
||||
yield takeLeading(LAB_ACTIONS.GET_UPDATES, getUpdates);
|
||||
yield takeLeading(LAB_ACTIONS.SEEN_NODE, seenNode);
|
||||
|
||||
yield takeLeading(LAB_ACTIONS.GET_MORE, getMore);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue