1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +07:00

getting flow diff

This commit is contained in:
Fedor Katurov 2019-11-18 15:15:41 +07:00
parent 971578bb21
commit 6641a03d92
4 changed files with 57 additions and 23 deletions

View file

@ -8,7 +8,7 @@ import {
} from "redux-saga/effects";
import { REHYDRATE } from "redux-persist";
import { FLOW_ACTIONS } from "./constants";
import { getNodes } from "../node/api";
import { getNodes, getNodeDiff } from "../node/api";
import {
flowSetNodes,
flowSetCellView,
@ -22,6 +22,8 @@ import { selectFlowNodes } from "./selectors";
import { reqWrapper } from "../auth/sagas";
import { postCellView } from "./api";
import { IFlowState } from "./reducer";
import uniqBy from "ramda/es/uniqBy";
import uniq from "ramda/es/uniq";
function* onGetFlow() {
yield put(flowSetFlow({ is_loading: true }));
@ -57,18 +59,24 @@ function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
function* getMore() {
yield put(flowSetFlow({ is_loading: true }));
const nodes: IFlowState["nodes"] = yield select(selectFlowNodes);
const from =
const start = nodes && nodes[0] && nodes[0].created_at;
const end =
nodes && nodes[nodes.length - 1] && nodes[nodes.length - 1].created_at;
const { error, data } = yield call(reqWrapper, getNodes, { from });
const { error, data } = yield call(reqWrapper, getNodeDiff, { start, end });
if (error || !data || !data.nodes) return;
if (error || !data) return;
yield put(
flowSetFlow({ is_loading: false, nodes: [...nodes, ...data.nodes] })
);
const result = uniq([
...(data.before || []),
...nodes,
...(data.after || [])
]);
yield delay(data.nodes.length > 0 ? 2000 : 30000);
yield put(flowSetFlow({ is_loading: false, nodes: result }));
yield delay(1000);
}
export default function* nodeSaga() {

View file

@ -34,6 +34,25 @@ export const getNodes = ({
.then(resultMiddleware)
.catch(errorMiddleware);
export const getNodeDiff = ({
start = null,
end = null,
take,
access
}: {
start?: string;
end?: string;
take?: number;
access: string;
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
api
.get(
API.NODE.GET_DIFF,
configWithToken(access, { params: { start, end, take } })
)
.then(resultMiddleware)
.catch(errorMiddleware);
export const getNode = ({
id,
access

View file

@ -43,6 +43,12 @@ const authPersistConfig: PersistConfig = {
storage
};
const flowPersistConfig: PersistConfig = {
key: "flow",
whitelist: ["nodes"],
storage
};
export interface IState {
auth: IAuthState;
modal: IModalState;
@ -76,7 +82,7 @@ export const store = createStore(
router: connectRouter(history),
node: nodeReducer,
uploads: uploadReducer,
flow: flowReducer,
flow: persistReducer(flowPersistConfig, flowReducer),
player: playerReducer
}),
composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware))