From 746d10ce8bcd0ecc1fbf193ce91d462931a57bba Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 28 Oct 2019 18:26:12 +0700 Subject: [PATCH] added recent to reducer --- src/components/flow/FlowGrid/index.tsx | 7 +++++-- src/components/flow/FlowRecent/index.tsx | 8 ++++++++ src/components/flow/FlowRecent/styles.scss | 3 +++ src/redux/flow/actions.ts | 5 +++++ src/redux/flow/constants.ts | 1 + src/redux/flow/handlers.ts | 6 +++++- src/redux/flow/reducer.ts | 2 ++ src/redux/flow/sagas.ts | 15 +++++++++------ 8 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 src/components/flow/FlowRecent/index.tsx create mode 100644 src/components/flow/FlowRecent/styles.scss diff --git a/src/components/flow/FlowGrid/index.tsx b/src/components/flow/FlowGrid/index.tsx index cb2aecdd..b7c3cdce 100644 --- a/src/components/flow/FlowGrid/index.tsx +++ b/src/components/flow/FlowGrid/index.tsx @@ -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 & { user: Partial; @@ -15,13 +16,15 @@ type IProps = Partial & { onChangeCellView: typeof flowSetCellView; }; -export const FlowGrid: FC = ({ user, nodes, heroes, onSelect, onChangeCellView }) => ( +export const FlowGrid: FC = ({ user, nodes, heroes, recent, onSelect, onChangeCellView }) => (
-
STAMP
+
+ +
{nodes.map(node => ( = ({}) =>
; + +export { FlowRecent }; diff --git a/src/components/flow/FlowRecent/styles.scss b/src/components/flow/FlowRecent/styles.scss new file mode 100644 index 00000000..4d942b9c --- /dev/null +++ b/src/components/flow/FlowRecent/styles.scss @@ -0,0 +1,3 @@ +.grid { + display: grid; +} \ No newline at end of file diff --git a/src/redux/flow/actions.ts b/src/redux/flow/actions.ts index 11b3b26b..51d3737a 100644 --- a/src/redux/flow/actions.ts +++ b/src/redux/flow/actions.ts @@ -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, diff --git a/src/redux/flow/constants.ts b/src/redux/flow/constants.ts index b74224b2..d350f7cb 100644 --- a/src/redux/flow/constants.ts +++ b/src/redux/flow/constants.ts @@ -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`, }; diff --git a/src/redux/flow/handlers.ts b/src/redux/flow/handlers.ts index d44ec537..2951bc89 100644 --- a/src/redux/flow/handlers.ts +++ b/src/redux/flow/handlers.ts @@ -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) => @@ -9,7 +9,11 @@ const setNodes = (state: IFlowState, { nodes }: ReturnType) const setHeroes = (state: IFlowState, { heroes }: ReturnType) => assocPath(['heroes'], heroes, state); +const setRecent = (state: IFlowState, { recent }: ReturnType) => + assocPath(['recent'], recent, state); + export const FLOW_HANDLERS = { [FLOW_ACTIONS.SET_NODES]: setNodes, [FLOW_ACTIONS.SET_HEROES]: setHeroes, + [FLOW_ACTIONS.SET_RECENT]: setRecent, }; diff --git a/src/redux/flow/reducer.ts b/src/redux/flow/reducer.ts index 6786076d..a5cc3845 100644 --- a/src/redux/flow/reducer.ts +++ b/src/redux/flow/reducer.ts @@ -6,12 +6,14 @@ export type IFlowState = Readonly<{ is_loading: boolean; nodes: INode[]; heroes: Partial[]; + recent: Partial[]; error: IError; }>; const INITIAL_STATE: IFlowState = { nodes: [], heroes: [], + recent: [], is_loading: false, error: null, }; diff --git a/src/redux/flow/sagas.ts b/src/redux/flow/sagas.ts index 56776a8f..89c41165 100644 --- a/src/redux/flow/sagas.ts +++ b/src/redux/flow/sagas.ts @@ -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) {