mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
diff loading for flow
This commit is contained in:
parent
3a34178ac4
commit
aa90258d25
4 changed files with 89 additions and 15 deletions
|
@ -25,8 +25,6 @@ render(
|
||||||
- friendship
|
- friendship
|
||||||
- password restore
|
- password restore
|
||||||
- signup?
|
- signup?
|
||||||
- flow updates
|
|
||||||
- flow infinite scroll
|
|
||||||
- avatar upload
|
- avatar upload
|
||||||
|
|
||||||
[stage 1]
|
[stage 1]
|
||||||
|
@ -42,6 +40,8 @@ render(
|
||||||
- comment editing
|
- comment editing
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
- flow updates
|
||||||
|
- flow infinite scroll
|
||||||
- better node brief update
|
- better node brief update
|
||||||
- fix: text nodes cell has no preview (actually, that's a problem of brief)
|
- fix: text nodes cell has no preview (actually, that's a problem of brief)
|
||||||
- relocate files
|
- relocate files
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "redux-saga/effects";
|
} from "redux-saga/effects";
|
||||||
import { REHYDRATE } from "redux-persist";
|
import { REHYDRATE } from "redux-persist";
|
||||||
import { FLOW_ACTIONS } from "./constants";
|
import { FLOW_ACTIONS } from "./constants";
|
||||||
import { getNodes, getNodeDiff } from "../node/api";
|
import { getNodeDiff } from "../node/api";
|
||||||
import {
|
import {
|
||||||
flowSetNodes,
|
flowSetNodes,
|
||||||
flowSetCellView,
|
flowSetCellView,
|
||||||
|
@ -17,13 +17,17 @@ import {
|
||||||
flowSetUpdated,
|
flowSetUpdated,
|
||||||
flowSetFlow
|
flowSetFlow
|
||||||
} from "./actions";
|
} from "./actions";
|
||||||
import { IResultWithStatus } 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() {
|
||||||
|
document.getElementById("main_loader").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
function* onGetFlow() {
|
function* onGetFlow() {
|
||||||
const {
|
const {
|
||||||
flow: { _persist }
|
flow: { _persist }
|
||||||
|
@ -31,25 +35,61 @@ function* onGetFlow() {
|
||||||
|
|
||||||
if (!_persist.rehydrated) return;
|
if (!_persist.rehydrated) return;
|
||||||
|
|
||||||
|
const stored: IFlowState["nodes"] = yield select(selectFlowNodes);
|
||||||
|
|
||||||
|
if (stored.length) {
|
||||||
|
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: { nodes = [], heroes = [], recent = [], updated = [], mode }
|
data: {
|
||||||
|
before = [],
|
||||||
|
after = [],
|
||||||
|
heroes = [],
|
||||||
|
recent = [],
|
||||||
|
updated = [],
|
||||||
|
valid = null
|
||||||
|
}
|
||||||
}: IResultWithStatus<{
|
}: IResultWithStatus<{
|
||||||
nodes: IFlowState["nodes"];
|
before: IFlowState["nodes"];
|
||||||
|
after: IFlowState["nodes"];
|
||||||
heroes: IFlowState["heroes"];
|
heroes: IFlowState["heroes"];
|
||||||
recent: IFlowState["recent"];
|
recent: IFlowState["recent"];
|
||||||
updated: IFlowState["updated"];
|
updated: IFlowState["updated"];
|
||||||
mode: string;
|
valid: INode["id"][];
|
||||||
}> = yield call(reqWrapper, getNodes, {});
|
}> = yield call(reqWrapper, getNodeDiff, {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
with_heroes: true,
|
||||||
|
with_updated: true,
|
||||||
|
with_recent: true,
|
||||||
|
with_valid: true
|
||||||
|
});
|
||||||
|
|
||||||
yield put(flowSetFlow({ is_loading: false, nodes }));
|
const result = uniq([
|
||||||
|
...(before || []),
|
||||||
|
...(valid ? stored.filter(node => valid.includes(node.id)) : stored),
|
||||||
|
...(after || [])
|
||||||
|
]);
|
||||||
|
|
||||||
|
yield put(flowSetFlow({ is_loading: false, nodes: result }));
|
||||||
|
|
||||||
if (heroes.length) yield put(flowSetHeroes(heroes));
|
if (heroes.length) yield put(flowSetHeroes(heroes));
|
||||||
if (recent.length) yield put(flowSetRecent(recent));
|
if (recent.length) yield put(flowSetRecent(recent));
|
||||||
if (updated.length) yield put(flowSetUpdated(updated));
|
if (updated.length) yield put(flowSetUpdated(updated));
|
||||||
|
|
||||||
document.getElementById("main_loader").style.display = "none";
|
if (!stored.length) hideLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
||||||
|
@ -69,17 +109,33 @@ function* getMore() {
|
||||||
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, { start, end });
|
const { error, data } = yield call(reqWrapper, getNodeDiff, {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
with_heroes: false,
|
||||||
|
with_updated: true,
|
||||||
|
with_recent: true,
|
||||||
|
with_valid: true
|
||||||
|
});
|
||||||
|
|
||||||
if (error || !data) return;
|
if (error || !data) return;
|
||||||
|
|
||||||
const result = uniq([
|
const result = uniq([
|
||||||
...(data.before || []),
|
...(data.before || []),
|
||||||
...nodes,
|
...(data.valid
|
||||||
|
? nodes.filter(node => data.valid.includes(node.id))
|
||||||
|
: nodes),
|
||||||
...(data.after || [])
|
...(data.after || [])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
yield put(flowSetFlow({ is_loading: false, nodes: result }));
|
yield put(
|
||||||
|
flowSetFlow({
|
||||||
|
is_loading: false,
|
||||||
|
nodes: result,
|
||||||
|
...(data.recent ? { recent: data.recent } : {}),
|
||||||
|
...(data.updated ? { updated: data.updated } : {})
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
yield delay(1000);
|
yield delay(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,17 +38,35 @@ export const getNodeDiff = ({
|
||||||
start = null,
|
start = null,
|
||||||
end = null,
|
end = null,
|
||||||
take,
|
take,
|
||||||
|
with_heroes,
|
||||||
|
with_updated,
|
||||||
|
with_recent,
|
||||||
|
with_valid,
|
||||||
access
|
access
|
||||||
}: {
|
}: {
|
||||||
start?: string;
|
start?: string;
|
||||||
end?: string;
|
end?: string;
|
||||||
take?: number;
|
take?: number;
|
||||||
access: string;
|
access: string;
|
||||||
|
with_heroes: boolean;
|
||||||
|
with_updated: boolean;
|
||||||
|
with_recent: boolean;
|
||||||
|
with_valid: boolean;
|
||||||
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
|
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
|
||||||
api
|
api
|
||||||
.get(
|
.get(
|
||||||
API.NODE.GET_DIFF,
|
API.NODE.GET_DIFF,
|
||||||
configWithToken(access, { params: { start, end, take } })
|
configWithToken(access, {
|
||||||
|
params: {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
take,
|
||||||
|
with_heroes,
|
||||||
|
with_updated,
|
||||||
|
with_recent,
|
||||||
|
with_valid
|
||||||
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.then(resultMiddleware)
|
.then(resultMiddleware)
|
||||||
.catch(errorMiddleware);
|
.catch(errorMiddleware);
|
||||||
|
|
|
@ -45,7 +45,7 @@ const authPersistConfig: PersistConfig = {
|
||||||
|
|
||||||
const flowPersistConfig: PersistConfig = {
|
const flowPersistConfig: PersistConfig = {
|
||||||
key: "flow",
|
key: "flow",
|
||||||
whitelist: ["nodes"],
|
whitelist: ["nodes", "heroes", "recent", "updated"],
|
||||||
storage
|
storage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue