1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

added nodes heroize button

This commit is contained in:
Fedor Katurov 2019-10-23 12:02:35 +07:00
parent c49dbb344d
commit 6b5638b44e
11 changed files with 140 additions and 47 deletions

View file

@ -80,6 +80,11 @@ export const nodeLike = (id: INode['id']) => ({
id,
});
export const nodeStar = (id: INode['id']) => ({
type: NODE_ACTIONS.STAR,
id,
});
export const nodeSetEditor = (editor: INode) => ({
type: NODE_ACTIONS.SET_EDITOR,
editor,

View file

@ -1,7 +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';
import { nodeUpdateTags, nodeLike, nodeStar } from './actions';
export const postNode = ({
access,
@ -79,10 +79,21 @@ export const updateNodeTags = ({
export const postNodeLike = ({
id,
access,
}: ReturnType<typeof nodeUpdateTags> & { access: string }): Promise<
}: ReturnType<typeof nodeLike> & { access: string }): Promise<
IResultWithStatus<{ is_liked: INode['is_liked'] }>
> =>
api
.post(API.NODE.POST_LIKE(id), {}, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);
export const postNodeStar = ({
id,
access,
}: ReturnType<typeof nodeStar> & { access: string }): Promise<
IResultWithStatus<{ is_liked: INode['is_liked'] }>
> =>
api
.post(API.NODE.POST_STAR(id), {}, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -21,6 +21,7 @@ export const NODE_ACTIONS = {
EDIT: `${prefix}EDIT`,
LIKE: `${prefix}LIKE`,
STAR: `${prefix}STAR`,
CREATE: `${prefix}CREATE`,
SET_SAVE_ERRORS: `${prefix}SET_SAVE_ERRORS`,

View file

@ -27,6 +27,7 @@ import {
getNodeComments,
updateNodeTags,
postNodeLike,
postNodeStar,
} from './api';
import { reqWrapper } from '../auth/sagas';
import { flowSetNodes } from '../flow/actions';
@ -197,6 +198,21 @@ function* onLikeSaga({ id }: ReturnType<typeof nodeLike>) {
yield call(updateNodeEverythere, { ...current, is_liked });
}
function* onStarSaga({ id }: ReturnType<typeof nodeLike>) {
const {
current,
current: { is_heroic },
} = yield select(selectNode);
yield call(updateNodeEverythere, { ...current, is_heroic: !is_heroic });
const { data, error } = yield call(reqWrapper, postNodeStar, { id });
if (!error || data.is_heroic === !is_heroic) return; // ok and matches
yield call(updateNodeEverythere, { ...current, is_heroic });
}
export default function* nodeSaga() {
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
yield takeLatest(NODE_ACTIONS.LOAD_NODE, onNodeLoad);
@ -205,4 +221,5 @@ export default function* nodeSaga() {
yield takeLatest(NODE_ACTIONS.CREATE, onCreateSaga);
yield takeLatest(NODE_ACTIONS.EDIT, onEditSaga);
yield takeLatest(NODE_ACTIONS.LIKE, onLikeSaga);
yield takeLatest(NODE_ACTIONS.STAR, onStarSaga);
}