1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

flow get more

This commit is contained in:
Fedor Katurov 2019-11-18 14:49:32 +07:00
parent f440a5f4c3
commit 971578bb21
11 changed files with 281 additions and 159 deletions

View file

@ -1,56 +1,78 @@
import { takeLatest, call, put, select } from 'redux-saga/effects';
import { REHYDRATE } from 'redux-persist';
import { FLOW_ACTIONS } from './constants';
import { getNodes } from '../node/api';
import {
takeLatest,
call,
put,
select,
takeLeading,
delay
} from "redux-saga/effects";
import { REHYDRATE } from "redux-persist";
import { FLOW_ACTIONS } from "./constants";
import { getNodes } from "../node/api";
import {
flowSetNodes,
flowSetCellView,
flowSetHeroes,
flowSetRecent,
flowSetUpdated,
} from './actions';
import { IResultWithStatus, INode } from '../types';
import { selectFlowNodes } from './selectors';
import { reqWrapper } from '../auth/sagas';
import { postCellView } from './api';
import { IFlowState } from './reducer';
flowSetFlow
} from "./actions";
import { IResultWithStatus } from "../types";
import { selectFlowNodes } from "./selectors";
import { reqWrapper } from "../auth/sagas";
import { postCellView } from "./api";
import { IFlowState } from "./reducer";
function* onGetFlow() {
yield put(flowSetFlow({ is_loading: true }));
const {
data: { nodes = [], heroes = [], recent = [], updated = [] },
data: { nodes = [], heroes = [], recent = [], updated = [], mode }
}: IResultWithStatus<{
nodes: IFlowState['nodes'];
heroes: IFlowState['heroes'];
recent: IFlowState['recent'];
updated: IFlowState['updated'];
nodes: IFlowState["nodes"];
heroes: IFlowState["heroes"];
recent: IFlowState["recent"];
updated: IFlowState["updated"];
mode: string;
}> = yield call(reqWrapper, getNodes, {});
// if (!nodes || !nodes.length) {
// yield put(flowSetNodes([]));
// yield put(flowSetHeroes([]));
// yield put(flowSetRecent([]));
// yield put(flowSetUpdated([]));
// return;
// }
yield put(flowSetFlow({ is_loading: false, nodes }));
yield put(flowSetNodes(nodes));
yield put(flowSetHeroes(heroes));
yield put(flowSetRecent(recent));
yield put(flowSetUpdated(updated));
if (heroes.length) yield put(flowSetHeroes(heroes));
if (recent.length) yield put(flowSetRecent(recent));
if (updated.length) yield put(flowSetUpdated(updated));
document.getElementById('main_loader').style.display = 'none';
document.getElementById("main_loader").style.display = "none";
}
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
const nodes = yield select(selectFlowNodes);
yield put(flowSetNodes(nodes.map(node => (node.id === id ? { ...node, flow } : node))));
yield put(
flowSetNodes(nodes.map(node => (node.id === id ? { ...node, flow } : node)))
);
const { data, error } = yield call(reqWrapper, postCellView, { id, flow });
}
console.log({ data, error });
function* getMore() {
yield put(flowSetFlow({ is_loading: true }));
const nodes: IFlowState["nodes"] = yield select(selectFlowNodes);
const from =
nodes && nodes[nodes.length - 1] && nodes[nodes.length - 1].created_at;
const { error, data } = yield call(reqWrapper, getNodes, { from });
if (error || !data || !data.nodes) return;
yield put(
flowSetFlow({ is_loading: false, nodes: [...nodes, ...data.nodes] })
);
yield delay(data.nodes.length > 0 ? 2000 : 30000);
}
export default function* nodeSaga() {
yield takeLatest([FLOW_ACTIONS.GET_FLOW, REHYDRATE], onGetFlow);
yield takeLatest(FLOW_ACTIONS.SET_CELL_VIEW, onSetCellView);
yield takeLeading(FLOW_ACTIONS.GET_MORE, getMore);
}