mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
added saga to change tags
This commit is contained in:
parent
033b5ca45d
commit
9df5e022dd
7 changed files with 44 additions and 11 deletions
|
@ -53,3 +53,9 @@ export const nodeSetCommentData = (id: number, comment: IComment) => ({
|
|||
comment,
|
||||
type: NODE_ACTIONS.SET_COMMENT_DATA,
|
||||
});
|
||||
|
||||
export const nodeUpdateTags = (id: INode['id'], tags: string[]) => ({
|
||||
type: NODE_ACTIONS.UPDATE_TAGS,
|
||||
id,
|
||||
tags,
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api';
|
||||
import { INode, IResultWithStatus, IComment } from '../types';
|
||||
import { API } from '~/constants/api';
|
||||
import { nodeUpdateTags } from './actions';
|
||||
|
||||
export const postNode = ({
|
||||
access,
|
||||
|
@ -57,3 +58,15 @@ export const getNodeComments = ({
|
|||
.get(API.NODE.COMMENT(id))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const updateNodeTags = ({
|
||||
id,
|
||||
tags,
|
||||
access,
|
||||
}: ReturnType<typeof nodeUpdateTags> & { access: string }): Promise<
|
||||
IResultWithStatus<{ node: INode }>
|
||||
> =>
|
||||
api
|
||||
.post(API.NODE.UPDATE_TAGS(id), { tags }, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
|
|
@ -16,6 +16,8 @@ export const NODE_ACTIONS = {
|
|||
|
||||
POST_COMMENT: `${prefix}POST_COMMENT`,
|
||||
SET_COMMENTS: `${prefix}SET_COMMENTS`,
|
||||
|
||||
UPDATE_TAGS: `${prefix}UPDATE_TAGS`,
|
||||
};
|
||||
|
||||
export const EMPTY_BLOCK: IBlock = {
|
||||
|
|
|
@ -13,8 +13,9 @@ import {
|
|||
nodeSetSendingComment,
|
||||
nodeSetComments,
|
||||
nodeSetCommentData,
|
||||
nodeUpdateTags,
|
||||
} from './actions';
|
||||
import { postNode, getNode, postNodeComment, getNodeComments } from './api';
|
||||
import { postNode, getNode, postNodeComment, getNodeComments, updateNodeTags } from './api';
|
||||
import { reqWrapper } from '../auth/sagas';
|
||||
import { flowSetNodes } from '../flow/actions';
|
||||
import { ERRORS } from '~/constants/errors';
|
||||
|
@ -102,8 +103,16 @@ function* onPostComment({ id }: ReturnType<typeof nodePostComment>) {
|
|||
}
|
||||
}
|
||||
|
||||
function* onUpdateTags({ id, tags }: ReturnType<typeof nodeUpdateTags>) {
|
||||
yield delay(1000);
|
||||
const result = yield call(reqWrapper, updateNodeTags, { id, tags });
|
||||
|
||||
console.log({ result });
|
||||
}
|
||||
|
||||
export default function* nodeSaga() {
|
||||
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
|
||||
yield takeLatest(NODE_ACTIONS.LOAD_NODE, onNodeLoad);
|
||||
yield takeLatest(NODE_ACTIONS.POST_COMMENT, onPostComment);
|
||||
yield takeLatest(NODE_ACTIONS.UPDATE_TAGS, onUpdateTags);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue