1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

added updated nodes to flow

This commit is contained in:
Fedor Katurov 2019-10-30 17:26:30 +07:00
parent 6f76bec2c0
commit 74cd181530
13 changed files with 128 additions and 30 deletions

View file

@ -17,6 +17,11 @@ export const flowSetRecent = (recent: IFlowState['recent']) => ({
type: FLOW_ACTIONS.SET_RECENT,
});
export const flowSetUpdated = (updated: IFlowState['updated']) => ({
updated,
type: FLOW_ACTIONS.SET_UPDATED,
});
export const flowSetCellView = (id: INode['id'], flow: INode['flow']) => ({
type: FLOW_ACTIONS.SET_CELL_VIEW,
id,

View file

@ -5,5 +5,6 @@ export const FLOW_ACTIONS = {
SET_NODES: `${prefix}SET_NODES`,
SET_HEROES: `${prefix}SET_HEROES`,
SET_RECENT: `${prefix}SET_RECENT`,
SET_UPDATED: `${prefix}SET_UPDATED`,
SET_CELL_VIEW: `${prefix}SET_CELL_VIEW`,
};

View file

@ -1,6 +1,6 @@
import assocPath from 'ramda/es/assocPath';
import { FLOW_ACTIONS } from './constants';
import { flowSetNodes, flowSetHeroes, flowSetRecent } from './actions';
import { flowSetNodes, flowSetHeroes, flowSetRecent, flowSetUpdated } from './actions';
import { IFlowState } from './reducer';
const setNodes = (state: IFlowState, { nodes }: ReturnType<typeof flowSetNodes>) =>
@ -12,8 +12,12 @@ const setHeroes = (state: IFlowState, { heroes }: ReturnType<typeof flowSetHeroe
const setRecent = (state: IFlowState, { recent }: ReturnType<typeof flowSetRecent>) =>
assocPath(['recent'], recent, state);
const setUpdated = (state: IFlowState, { updated }: ReturnType<typeof flowSetUpdated>) =>
assocPath(['updated'], updated, state);
export const FLOW_HANDLERS = {
[FLOW_ACTIONS.SET_NODES]: setNodes,
[FLOW_ACTIONS.SET_HEROES]: setHeroes,
[FLOW_ACTIONS.SET_RECENT]: setRecent,
[FLOW_ACTIONS.SET_UPDATED]: setUpdated,
};

View file

@ -7,6 +7,7 @@ export type IFlowState = Readonly<{
nodes: INode[];
heroes: Partial<INode>[];
recent: Partial<INode>[];
updated: Partial<INode>[];
error: IError;
}>;
@ -14,6 +15,7 @@ const INITIAL_STATE: IFlowState = {
nodes: [],
heroes: [],
recent: [],
updated: [],
is_loading: false,
error: null,
};

View file

@ -2,7 +2,13 @@ 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 { flowSetNodes, flowSetCellView, flowSetHeroes, flowSetRecent } from './actions';
import {
flowSetNodes,
flowSetCellView,
flowSetHeroes,
flowSetRecent,
flowSetUpdated,
} from './actions';
import { IResultWithStatus, INode } from '../types';
import { selectFlowNodes } from './selectors';
import { reqWrapper } from '../auth/sagas';
@ -11,23 +17,26 @@ import { IFlowState } from './reducer';
function* onGetFlow() {
const {
data: { nodes = null, heroes = null, recent = null },
data: { nodes = null, heroes = null, recent = [], updated = [] },
}: IResultWithStatus<{
nodes: IFlowState['nodes'];
heroes: IFlowState['heroes'];
recent: IFlowState['recent'];
}> = yield call(getNodes, {});
updated: IFlowState['updated'];
}> = yield call(reqWrapper, getNodes, {});
if (!nodes || !nodes.length) {
yield put(flowSetNodes([]));
yield put(flowSetHeroes([]));
yield put(flowSetRecent([]));
yield put(flowSetUpdated([]));
return;
}
yield put(flowSetNodes(nodes));
yield put(flowSetHeroes(heroes));
yield put(flowSetRecent(recent));
yield put(flowSetUpdated(updated));
}
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {

View file

@ -19,11 +19,13 @@ export const postNode = ({
export const getNodes = ({
skip = 0,
access,
}: {
skip?: number;
access: string;
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
api
.get(API.NODE.GET, { params: { skip } })
.get(API.NODE.GET, configWithToken(access, { params: { skip } }))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -129,8 +129,9 @@ export interface INode {
tags: ITag[];
createdAt?: string;
updatedAt?: string;
created_at?: string;
updated_at?: string;
commented_at?: string;
}
export interface IComment {