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

loading node

This commit is contained in:
muerwre 2019-08-25 17:04:13 +07:00
parent da9ac62584
commit a0272f5baa
4 changed files with 28 additions and 5 deletions

View file

@ -12,9 +12,11 @@ interface IProps {
} }
const NodeImageBlock: FC<IProps> = ({ node, is_loading }) => { const NodeImageBlock: FC<IProps> = ({ node, is_loading }) => {
const images = useMemo(() => node.files.filter(({ type }) => type === UPLOAD_TYPES.IMAGE), [ const images = useMemo(
node, () =>
]); (node && node.files && node.files.filter(({ type }) => type === UPLOAD_TYPES.IMAGE)) || [],
[node]
);
return ( return (
<div className={classNames(styles.wrap, { is_loading })}> <div className={classNames(styles.wrap, { is_loading })}>

View file

@ -8,5 +8,6 @@ export const API = {
NODE: { NODE: {
SAVE: '/node/', SAVE: '/node/',
GET: '/node/', GET: '/node/',
GET_NODE: (id: number | string) => `/node/${id}`,
}, },
}; };

View file

@ -23,3 +23,13 @@ export const getNodes = ({
.get(API.NODE.GET, { params: { skip } }) .get(API.NODE.GET, { params: { skip } })
.then(resultMiddleware) .then(resultMiddleware)
.catch(errorMiddleware); .catch(errorMiddleware);
export const getNode = ({
id,
}: {
id: string | number;
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
api
.get(API.NODE.GET_NODE(id))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -9,7 +9,7 @@ import {
nodeSetLoading, nodeSetLoading,
nodeSetCurrent, nodeSetCurrent,
} from './actions'; } from './actions';
import { postNode } from './api'; import { postNode, getNode } from './api';
import { reqWrapper } from '../auth/sagas'; import { reqWrapper } from '../auth/sagas';
import { flowSetNodes } from '../flow/actions'; import { flowSetNodes } from '../flow/actions';
import { ERRORS } from '~/constants/errors'; import { ERRORS } from '~/constants/errors';
@ -45,10 +45,20 @@ function* onNodeLoad({ id, node_type }: ReturnType<typeof nodeLoadNode>) {
yield put(push(URLS.NODE_URL(id))); yield put(push(URLS.NODE_URL(id)));
yield delay(1000); const {
data: { node, error },
} = yield call(getNode, { id });
yield put(nodeSetLoading(false)); yield put(nodeSetLoading(false));
if (error) {
return yield put(nodeSetSaveErrors({ error }));
}
yield put(nodeSetSaveErrors({})); yield put(nodeSetSaveErrors({}));
yield put(nodeSetCurrent(node));
return;
} }
export default function* nodeSaga() { export default function* nodeSaga() {