1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

added recent to reducer

This commit is contained in:
Fedor Katurov 2019-10-28 18:26:12 +07:00
parent 920a8adaa2
commit 746d10ce8b
8 changed files with 38 additions and 9 deletions

View file

@ -8,6 +8,7 @@ import { canEditNode } from '~/utils/node';
import { IUser } from '~/redux/auth/types';
import { flowSetCellView } from '~/redux/flow/actions';
import { FlowHero } from '../FlowHero';
import { FlowRecent } from '../FlowRecent';
type IProps = Partial<IFlowState> & {
user: Partial<IUser>;
@ -15,13 +16,15 @@ type IProps = Partial<IFlowState> & {
onChangeCellView: typeof flowSetCellView;
};
export const FlowGrid: FC<IProps> = ({ user, nodes, heroes, onSelect, onChangeCellView }) => (
export const FlowGrid: FC<IProps> = ({ user, nodes, heroes, recent, onSelect, onChangeCellView }) => (
<div>
<div className={styles.grid_test}>
<div className={styles.hero}>
<FlowHero heroes={heroes} />
</div>
<div className={styles.stamp}>STAMP</div>
<div className={styles.stamp}>
<FlowRecent />
</div>
{nodes.map(node => (
<Cell

View file

@ -0,0 +1,8 @@
import React, { FC } from 'react';
import * as styles from './styles.scss';
interface IProps {}
const FlowRecent: FC<IProps> = ({}) => <div className={styles.grid} />;
export { FlowRecent };

View file

@ -0,0 +1,3 @@
.grid {
display: grid;
}

View file

@ -12,6 +12,11 @@ export const flowSetHeroes = (heroes: IFlowState['heroes']) => ({
type: FLOW_ACTIONS.SET_HEROES,
});
export const flowSetRecent = (recent: IFlowState['recent']) => ({
recent,
type: FLOW_ACTIONS.SET_RECENT,
});
export const flowSetCellView = (id: INode['id'], flow: INode['flow']) => ({
type: FLOW_ACTIONS.SET_CELL_VIEW,
id,

View file

@ -4,5 +4,6 @@ export const FLOW_ACTIONS = {
GET_FLOW: `${prefix}GET_FLOW`,
SET_NODES: `${prefix}SET_NODES`,
SET_HEROES: `${prefix}SET_HEROES`,
SET_RECENT: `${prefix}SET_RECENT`,
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 } from './actions';
import { flowSetNodes, flowSetHeroes, flowSetRecent } from './actions';
import { IFlowState } from './reducer';
const setNodes = (state: IFlowState, { nodes }: ReturnType<typeof flowSetNodes>) =>
@ -9,7 +9,11 @@ const setNodes = (state: IFlowState, { nodes }: ReturnType<typeof flowSetNodes>)
const setHeroes = (state: IFlowState, { heroes }: ReturnType<typeof flowSetHeroes>) =>
assocPath(['heroes'], heroes, state);
const setRecent = (state: IFlowState, { recent }: ReturnType<typeof flowSetRecent>) =>
assocPath(['recent'], recent, state);
export const FLOW_HANDLERS = {
[FLOW_ACTIONS.SET_NODES]: setNodes,
[FLOW_ACTIONS.SET_HEROES]: setHeroes,
[FLOW_ACTIONS.SET_RECENT]: setRecent,
};

View file

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

View file

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