mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
cleanup
This commit is contained in:
parent
a759566590
commit
5340f04a93
1 changed files with 33 additions and 63 deletions
|
@ -1,87 +1,60 @@
|
||||||
import {
|
import { takeLatest, call, put, select, takeLeading, delay } from 'redux-saga/effects';
|
||||||
takeLatest,
|
import { REHYDRATE } from 'redux-persist';
|
||||||
call,
|
import { FLOW_ACTIONS } from './constants';
|
||||||
put,
|
import { getNodeDiff } from '../node/api';
|
||||||
select,
|
|
||||||
takeLeading,
|
|
||||||
delay
|
|
||||||
} from "redux-saga/effects";
|
|
||||||
import { REHYDRATE } from "redux-persist";
|
|
||||||
import { FLOW_ACTIONS } from "./constants";
|
|
||||||
import { getNodeDiff } from "../node/api";
|
|
||||||
import {
|
import {
|
||||||
flowSetNodes,
|
flowSetNodes,
|
||||||
flowSetCellView,
|
flowSetCellView,
|
||||||
flowSetHeroes,
|
flowSetHeroes,
|
||||||
flowSetRecent,
|
flowSetRecent,
|
||||||
flowSetUpdated,
|
flowSetUpdated,
|
||||||
flowSetFlow
|
flowSetFlow,
|
||||||
} from "./actions";
|
} from './actions';
|
||||||
import { IResultWithStatus, INode } from "../types";
|
import { IResultWithStatus, INode } from '../types';
|
||||||
import { selectFlowNodes } from "./selectors";
|
import { selectFlowNodes } from './selectors';
|
||||||
import { reqWrapper } from "../auth/sagas";
|
import { reqWrapper } from '../auth/sagas';
|
||||||
import { postCellView } from "./api";
|
import { postCellView } from './api';
|
||||||
import { IFlowState } from "./reducer";
|
import { IFlowState } from './reducer';
|
||||||
import uniq from "ramda/es/uniq";
|
import uniq from 'ramda/es/uniq';
|
||||||
|
|
||||||
function hideLoader() {
|
function hideLoader() {
|
||||||
document.getElementById("main_loader").style.display = "none";
|
document.getElementById('main_loader').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
function* onGetFlow() {
|
function* onGetFlow() {
|
||||||
const {
|
const {
|
||||||
flow: { _persist }
|
flow: { _persist },
|
||||||
} = yield select();
|
} = yield select();
|
||||||
|
|
||||||
if (!_persist.rehydrated) return;
|
if (!_persist.rehydrated) return;
|
||||||
|
|
||||||
const stored: IFlowState["nodes"] = yield select(selectFlowNodes);
|
const stored: IFlowState['nodes'] = yield select(selectFlowNodes);
|
||||||
|
|
||||||
if (stored.length) {
|
if (stored.length) {
|
||||||
hideLoader();
|
hideLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
// const start =
|
|
||||||
// (stored && stored[0] && stored[0].created_at) || new Date().toISOString();
|
|
||||||
//
|
|
||||||
// const end =
|
|
||||||
// (stored &&
|
|
||||||
// stored[stored.length - 1] &&
|
|
||||||
// stored[stored.length - 1].created_at) ||
|
|
||||||
// new Date().toISOString();
|
|
||||||
|
|
||||||
yield put(flowSetFlow({ is_loading: true }));
|
yield put(flowSetFlow({ is_loading: true }));
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: {
|
data: { before = [], after = [], heroes = [], recent = [], updated = [], valid = null },
|
||||||
before = [],
|
|
||||||
after = [],
|
|
||||||
heroes = [],
|
|
||||||
recent = [],
|
|
||||||
updated = [],
|
|
||||||
valid = null
|
|
||||||
}
|
|
||||||
}: IResultWithStatus<{
|
}: IResultWithStatus<{
|
||||||
before: IFlowState["nodes"];
|
before: IFlowState['nodes'];
|
||||||
after: IFlowState["nodes"];
|
after: IFlowState['nodes'];
|
||||||
heroes: IFlowState["heroes"];
|
heroes: IFlowState['heroes'];
|
||||||
recent: IFlowState["recent"];
|
recent: IFlowState['recent'];
|
||||||
updated: IFlowState["updated"];
|
updated: IFlowState['updated'];
|
||||||
valid: INode["id"][];
|
valid: INode['id'][];
|
||||||
}> = yield call(reqWrapper, getNodeDiff, {
|
}> = yield call(reqWrapper, getNodeDiff, {
|
||||||
start: new Date().toISOString(),
|
start: new Date().toISOString(),
|
||||||
end: new Date().toISOString(),
|
end: new Date().toISOString(),
|
||||||
with_heroes: true,
|
with_heroes: true,
|
||||||
with_updated: true,
|
with_updated: true,
|
||||||
with_recent: true,
|
with_recent: true,
|
||||||
with_valid: false
|
with_valid: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = uniq([
|
const result = uniq([...(before || []), ...(after || [])]);
|
||||||
...(before || []),
|
|
||||||
// ...(valid ? stored.filter(node => valid.includes(node.id)) : stored),
|
|
||||||
...(after || [])
|
|
||||||
]);
|
|
||||||
|
|
||||||
yield put(flowSetFlow({ is_loading: false, nodes: result }));
|
yield put(flowSetFlow({ is_loading: false, nodes: result }));
|
||||||
|
|
||||||
|
@ -94,20 +67,19 @@ function* onGetFlow() {
|
||||||
|
|
||||||
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
||||||
const nodes = yield select(selectFlowNodes);
|
const nodes = yield select(selectFlowNodes);
|
||||||
yield put(
|
yield put(flowSetNodes(nodes.map(node => (node.id === id ? { ...node, flow } : node))));
|
||||||
flowSetNodes(nodes.map(node => (node.id === id ? { ...node, flow } : node)))
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data, error } = yield call(reqWrapper, postCellView, { id, flow });
|
const { data, error } = yield call(reqWrapper, postCellView, { id, flow });
|
||||||
|
|
||||||
|
// TODO: error handling
|
||||||
}
|
}
|
||||||
|
|
||||||
function* getMore() {
|
function* getMore() {
|
||||||
yield put(flowSetFlow({ is_loading: true }));
|
yield put(flowSetFlow({ is_loading: true }));
|
||||||
const nodes: IFlowState["nodes"] = yield select(selectFlowNodes);
|
const nodes: IFlowState['nodes'] = yield select(selectFlowNodes);
|
||||||
|
|
||||||
const start = nodes && nodes[0] && nodes[0].created_at;
|
const start = nodes && nodes[0] && nodes[0].created_at;
|
||||||
const end =
|
const end = nodes && nodes[nodes.length - 1] && nodes[nodes.length - 1].created_at;
|
||||||
nodes && nodes[nodes.length - 1] && nodes[nodes.length - 1].created_at;
|
|
||||||
|
|
||||||
const { error, data } = yield call(reqWrapper, getNodeDiff, {
|
const { error, data } = yield call(reqWrapper, getNodeDiff, {
|
||||||
start,
|
start,
|
||||||
|
@ -115,17 +87,15 @@ function* getMore() {
|
||||||
with_heroes: false,
|
with_heroes: false,
|
||||||
with_updated: true,
|
with_updated: true,
|
||||||
with_recent: true,
|
with_recent: true,
|
||||||
with_valid: true
|
with_valid: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error || !data) return;
|
if (error || !data) return;
|
||||||
|
|
||||||
const result = uniq([
|
const result = uniq([
|
||||||
...(data.before || []),
|
...(data.before || []),
|
||||||
...(data.valid
|
...(data.valid ? nodes.filter(node => data.valid.includes(node.id)) : nodes),
|
||||||
? nodes.filter(node => data.valid.includes(node.id))
|
...(data.after || []),
|
||||||
: nodes),
|
|
||||||
...(data.after || [])
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
yield put(
|
yield put(
|
||||||
|
@ -133,7 +103,7 @@ function* getMore() {
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
nodes: result,
|
nodes: result,
|
||||||
...(data.recent ? { recent: data.recent } : {}),
|
...(data.recent ? { recent: data.recent } : {}),
|
||||||
...(data.updated ? { updated: data.updated } : {})
|
...(data.updated ? { updated: data.updated } : {}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue