1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

comment deletion

This commit is contained in:
Fedor Katurov 2019-11-29 12:32:44 +07:00
parent 59d544c5f4
commit cf30f13eff
5 changed files with 49 additions and 11 deletions

View file

@ -25,14 +25,18 @@ const Comment: FC<IProps> = memo(
{...props} {...props}
> >
<div className={styles.wrap}> <div className={styles.wrap}>
{comment_group.comments.map(comment => ( {comment_group.comments.map(comment =>
<CommentContent comment.deleted_at ? (
comment={comment} <div key={comment.id}>deleted</div>
key={comment.id} ) : (
can_edit={can_edit} <CommentContent
onDelete={onDelete} comment={comment}
/> key={comment.id}
))} can_edit={can_edit}
onDelete={onDelete}
/>
)
)}
</div> </div>
</CommentWrapper> </CommentWrapper>
); );

View file

@ -38,7 +38,7 @@ const CommentContent: FC<IProps> = memo(({ comment, can_edit, onDelete }) => {
const lock = useMemo( const lock = useMemo(
() => () =>
can_edit ? ( can_edit ? (
<div className={styles.lock}> <div className={styles.lock} onClick={onLockClick}>
<div> <div>
<Icon icon="close" /> <Icon icon="close" />
</div> </div>

View file

@ -1,4 +1,4 @@
import { INode } from '~/redux/types'; import { INode, IComment } from '~/redux/types';
export const API = { export const API = {
BASE: process.env.API_HOST, BASE: process.env.API_HOST,
@ -26,6 +26,8 @@ export const API = {
POST_LIKE: (id: INode['id']) => `/node/${id}/like`, POST_LIKE: (id: INode['id']) => `/node/${id}/like`,
POST_STAR: (id: INode['id']) => `/node/${id}/heroic`, POST_STAR: (id: INode['id']) => `/node/${id}/heroic`,
POST_LOCK: (id: INode['id']) => `/node/${id}/lock`, POST_LOCK: (id: INode['id']) => `/node/${id}/lock`,
POST_LOCK_COMMENT: (id: INode['id'], comment_id: IComment['id']) =>
`/node/${id}/comment/${comment_id}/lock`,
SET_CELL_VIEW: (id: INode['id']) => `/node/${id}/cell-view`, SET_CELL_VIEW: (id: INode['id']) => `/node/${id}/cell-view`,
}, },
}; };

View file

@ -1,7 +1,7 @@
import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api'; import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api';
import { INode, IResultWithStatus, IComment } from '../types'; import { INode, IResultWithStatus, IComment } from '../types';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { nodeUpdateTags, nodeLike, nodeStar, nodeLock } from './actions'; import { nodeUpdateTags, nodeLike, nodeStar, nodeLock, nodeLockComment } from './actions';
import { INodeState } from './reducer'; import { INodeState } from './reducer';
export const postNode = ({ export const postNode = ({
@ -163,3 +163,16 @@ export const postNodeLock = ({
.post(API.NODE.POST_LOCK(id), { is_locked }, configWithToken(access)) .post(API.NODE.POST_LOCK(id), { is_locked }, configWithToken(access))
.then(resultMiddleware) .then(resultMiddleware)
.catch(errorMiddleware); .catch(errorMiddleware);
export const postNodeLockComment = ({
id,
is_locked,
current,
access,
}: ReturnType<typeof nodeLockComment> & { access: string; current: INode['id'] }): Promise<
IResultWithStatus<{ deleted_at: INode['deleted_at'] }>
> =>
api
.post(API.NODE.POST_LOCK_COMMENT(current, id), { is_locked }, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -22,6 +22,7 @@ import {
nodeSetRelated, nodeSetRelated,
nodeGotoNode, nodeGotoNode,
nodeLock, nodeLock,
nodeLockComment,
} from './actions'; } from './actions';
import { import {
postNode, postNode,
@ -33,6 +34,7 @@ import {
postNodeStar, postNodeStar,
getNodeRelated, getNodeRelated,
postNodeLock, postNodeLock,
postNodeLockComment,
} from './api'; } from './api';
import { reqWrapper } from '../auth/sagas'; import { reqWrapper } from '../auth/sagas';
import { flowSetNodes, flowSetUpdated } from '../flow/actions'; import { flowSetNodes, flowSetUpdated } from '../flow/actions';
@ -256,6 +258,22 @@ function* onLockSaga({ id, is_locked }: ReturnType<typeof nodeLock>) {
if (error) return yield call(updateNodeEverywhere, { ...current, deleted_at }); if (error) return yield call(updateNodeEverywhere, { ...current, deleted_at });
} }
function* onLockCommentSaga({ id, is_locked }: ReturnType<typeof nodeLockComment>) {
const { current, comments } = yield select(selectNode);
yield put(
nodeSetComments(
comments.map(comment =>
comment.id === id
? { ...comment, deleted_at: is_locked ? new Date().toISOString() : null }
: comment
)
)
);
yield call(reqWrapper, postNodeLockComment, { current: current.id, id, is_locked });
}
export default function* nodeSaga() { export default function* nodeSaga() {
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave); yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto); yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto);
@ -267,4 +285,5 @@ export default function* nodeSaga() {
yield takeLatest(NODE_ACTIONS.LIKE, onLikeSaga); yield takeLatest(NODE_ACTIONS.LIKE, onLikeSaga);
yield takeLatest(NODE_ACTIONS.STAR, onStarSaga); yield takeLatest(NODE_ACTIONS.STAR, onStarSaga);
yield takeLatest(NODE_ACTIONS.LOCK, onLockSaga); yield takeLatest(NODE_ACTIONS.LOCK, onLockSaga);
yield takeLatest(NODE_ACTIONS.LOCK_COMMENT, onLockCommentSaga);
} }