mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
getting flow diff
This commit is contained in:
parent
971578bb21
commit
6641a03d92
4 changed files with 57 additions and 23 deletions
|
@ -1,28 +1,29 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import { INode } from "~/redux/types";
|
||||
|
||||
export const API = {
|
||||
BASE: process.env.API_HOST,
|
||||
USER: {
|
||||
LOGIN: '/user/login',
|
||||
LOGIN: "/user/login",
|
||||
VKONTAKTE_LOGIN: `${process.env.API_HOST}/user/vkontakte`,
|
||||
ME: '/user/',
|
||||
ME: "/user/",
|
||||
PROFILE: (username: string) => `/user/${username}/profile`,
|
||||
MESSAGES: (username: string) => `/user/${username}/messages`,
|
||||
MESSAGE_SEND: (username: string) => `/user/${username}/messages`,
|
||||
GET_UPDATES: '/user/updates',
|
||||
GET_UPDATES: "/user/updates",
|
||||
|
||||
UPLOAD: (target, type) => `/upload/${target}/${type}`,
|
||||
UPLOAD: (target, type) => `/upload/${target}/${type}`
|
||||
},
|
||||
NODE: {
|
||||
SAVE: '/node/',
|
||||
GET: '/node/',
|
||||
SAVE: "/node/",
|
||||
GET: "/node/",
|
||||
GET_DIFF: "/node/diff",
|
||||
GET_NODE: (id: number | string) => `/node/${id}`,
|
||||
|
||||
COMMENT: (id: INode['id']) => `/node/${id}/comment`,
|
||||
RELATED: (id: INode['id']) => `/node/${id}/related`,
|
||||
UPDATE_TAGS: (id: INode['id']) => `/node/${id}/tags`,
|
||||
POST_LIKE: (id: INode['id']) => `/node/${id}/like`,
|
||||
POST_STAR: (id: INode['id']) => `/node/${id}/heroic`,
|
||||
SET_CELL_VIEW: (id: INode['id']) => `/node/${id}/cell-view`,
|
||||
},
|
||||
COMMENT: (id: INode["id"]) => `/node/${id}/comment`,
|
||||
RELATED: (id: INode["id"]) => `/node/${id}/related`,
|
||||
UPDATE_TAGS: (id: INode["id"]) => `/node/${id}/tags`,
|
||||
POST_LIKE: (id: INode["id"]) => `/node/${id}/like`,
|
||||
POST_STAR: (id: INode["id"]) => `/node/${id}/heroic`,
|
||||
SET_CELL_VIEW: (id: INode["id"]) => `/node/${id}/cell-view`
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue