From 1d40eca79e1c3f7c8104fcf37d783fccf6e02975 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 23 Oct 2019 15:36:25 +0700 Subject: [PATCH] storing flow cell view --- .vscode/settings.json | 1 + src/components/flow/Cell/index.tsx | 8 ++++---- src/constants/api.ts | 1 + src/redux/flow/api.ts | 13 +++++++++++++ src/redux/flow/sagas.ts | 8 ++++++-- tsconfig.json | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d7177d71..3d65345e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,4 +17,5 @@ "editor.formatOnSave": true, "editor.formatOnSaveTimeout": 750, }, + "typescript.tsdk": "node_modules/typescript/lib", } diff --git a/src/components/flow/Cell/index.tsx b/src/components/flow/Cell/index.tsx index 0e80c541..df7e67be 100644 --- a/src/components/flow/Cell/index.tsx +++ b/src/components/flow/Cell/index.tsx @@ -39,22 +39,22 @@ const Cell: FC = ({ }, [id, flow, onChangeCellView]); const setViewSingle = useCallback(() => { - const show_description = flow && !!flow.show_description; + const show_description = (flow && !!flow.show_description) || false; onChangeCellView(id, { show_description, display: 'single' }); }, [id, flow, onChangeCellView]); const setViewHorizontal = useCallback(() => { - const show_description = flow && !!flow.show_description; + const show_description = (flow && !!flow.show_description) || false; onChangeCellView(id, { show_description, display: 'horizontal' }); }, [id, flow, onChangeCellView]); const setViewVertical = useCallback(() => { - const show_description = flow && !!flow.show_description; + const show_description = (flow && !!flow.show_description) || false; onChangeCellView(id, { show_description, display: 'vertical' }); }, [id, flow, onChangeCellView]); const setViewQuadro = useCallback(() => { - const show_description = flow && !!flow.show_description; + const show_description = (flow && !!flow.show_description) || false; onChangeCellView(id, { show_description, display: 'quadro' }); }, [id, flow, onChangeCellView]); diff --git a/src/constants/api.ts b/src/constants/api.ts index a83ce381..32a7b62a 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -16,5 +16,6 @@ export const API = { 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`, }, }; diff --git a/src/redux/flow/api.ts b/src/redux/flow/api.ts index b15e5d7c..17145b59 100644 --- a/src/redux/flow/api.ts +++ b/src/redux/flow/api.ts @@ -1,6 +1,7 @@ import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api'; import { INode, IResultWithStatus } from '../types'; import { API } from '~/constants/api'; +import { flowSetCellView } from '~/redux/flow/actions'; export const postNode = ({ access, @@ -23,3 +24,15 @@ export const getNodes = ({ .get(API.NODE.GET, { params: { skip } }) .then(resultMiddleware) .catch(errorMiddleware); + +export const postCellView = ({ + id, + flow, + access, +}: ReturnType & { access: string }): Promise< + IResultWithStatus<{ is_liked: INode['is_liked'] }> +> => + api + .post(API.NODE.SET_CELL_VIEW(id), { flow }, configWithToken(access)) + .then(resultMiddleware) + .catch(errorMiddleware); diff --git a/src/redux/flow/sagas.ts b/src/redux/flow/sagas.ts index 377b7fa5..9c8aa710 100644 --- a/src/redux/flow/sagas.ts +++ b/src/redux/flow/sagas.ts @@ -4,13 +4,13 @@ import { FLOW_ACTIONS } from './constants'; import { getNodes } from '../node/api'; import { flowSetNodes, flowSetCellView } from './actions'; import { IResultWithStatus, INode } from '../types'; -import { updateNodeEverywhere } from '../node/sagas'; import { selectFlowNodes } from './selectors'; +import { reqWrapper } from '../auth/sagas'; +import { postCellView } from './api'; function* onGetFlow() { const { data: { nodes = null }, - error, }: IResultWithStatus<{ nodes: INode[] }> = yield call(getNodes, {}); if (!nodes || !nodes.length) { @@ -24,6 +24,10 @@ function* onGetFlow() { function* onSetCellView({ id, flow }: ReturnType) { const nodes = yield select(selectFlowNodes); yield put(flowSetNodes(nodes.map(node => (node.id === id ? { ...node, flow } : node)))); + + const { data, error } = yield call(reqWrapper, postCellView, { id, flow }); + + console.log({ data, error }); } export default function* nodeSaga() { diff --git a/tsconfig.json b/tsconfig.json index 3b6d8e22..85e2c5c5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,6 @@ "~/*": ["src/*"] } }, - "include": ["./src/index.tsx", "./custom.d.ts"], + "include": ["./src/**/*.ts", "./src/**/*.tsx", "./custom.d.ts"], "exclude": ["./__tests__/**/*"] }