1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

storing flow cell view

This commit is contained in:
Fedor Katurov 2019-10-23 15:36:25 +07:00
parent 7254a448c1
commit 1d40eca79e
6 changed files with 26 additions and 7 deletions

View file

@ -17,4 +17,5 @@
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 750,
},
"typescript.tsdk": "node_modules/typescript/lib",
}

View file

@ -39,22 +39,22 @@ const Cell: FC<IProps> = ({
}, [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]);

View file

@ -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`,
},
};

View file

@ -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<typeof flowSetCellView> & { access: string }): Promise<
IResultWithStatus<{ is_liked: INode['is_liked'] }>
> =>
api
.post(API.NODE.SET_CELL_VIEW(id), { flow }, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -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<typeof flowSetCellView>) {
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() {

View file

@ -18,6 +18,6 @@
"~/*": ["src/*"]
}
},
"include": ["./src/index.tsx", "./custom.d.ts"],
"include": ["./src/**/*.ts", "./src/**/*.tsx", "./custom.d.ts"],
"exclude": ["./__tests__/**/*"]
}