mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
comment menu
This commit is contained in:
parent
ab898cc40c
commit
1bf9fe6b83
14 changed files with 319 additions and 98 deletions
|
@ -2,6 +2,11 @@ import { INode, IValidationErrors, IComment, ITag, IFile } from '../types';
|
|||
import { NODE_ACTIONS, NODE_TYPES } from './constants';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
export const nodeSet = (node: Partial<INodeState>) => ({
|
||||
node,
|
||||
type: NODE_ACTIONS.SET,
|
||||
});
|
||||
|
||||
export const nodeSave = (node: INode) => ({
|
||||
node,
|
||||
type: NODE_ACTIONS.SAVE,
|
||||
|
@ -109,6 +114,11 @@ export const nodeLockComment = (id: IComment['id'], is_locked: boolean) => ({
|
|||
is_locked,
|
||||
});
|
||||
|
||||
export const nodeEditComment = (id: IComment['id']) => ({
|
||||
type: NODE_ACTIONS.EDIT_COMMENT,
|
||||
id,
|
||||
});
|
||||
|
||||
export const nodeSetEditor = (editor: INode) => ({
|
||||
type: NODE_ACTIONS.SET_EDITOR,
|
||||
editor,
|
||||
|
|
|
@ -19,12 +19,14 @@ export const NODE_ACTIONS = {
|
|||
SAVE: `${prefix}SAVE`,
|
||||
LOAD_NODE: `${prefix}LOAD_NODE`,
|
||||
GOTO_NODE: `${prefix}GOTO_NODE`,
|
||||
SET: `${prefix}SET`,
|
||||
|
||||
EDIT: `${prefix}EDIT`,
|
||||
LIKE: `${prefix}LIKE`,
|
||||
STAR: `${prefix}STAR`,
|
||||
LOCK: `${prefix}LOCK`,
|
||||
LOCK_COMMENT: `${prefix}LOCK_COMMENT`,
|
||||
EDIT_COMMENT: `${prefix}EDIT_COMMENT`,
|
||||
CREATE: `${prefix}CREATE`,
|
||||
|
||||
SET_SAVE_ERRORS: `${prefix}SET_SAVE_ERRORS`,
|
||||
|
|
|
@ -12,9 +12,15 @@ import {
|
|||
nodeSetEditor,
|
||||
nodeSetCoverImage,
|
||||
nodeSetRelated,
|
||||
nodeSet,
|
||||
} from './actions';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
const setData = (state: INodeState, { node }: ReturnType<typeof nodeSet>) => ({
|
||||
...state,
|
||||
...node,
|
||||
});
|
||||
|
||||
const setSaveErrors = (state: INodeState, { errors }: ReturnType<typeof nodeSetSaveErrors>) =>
|
||||
assocPath(['errors'], errors, state);
|
||||
|
||||
|
@ -57,6 +63,7 @@ const setCoverImage = (
|
|||
) => assocPath(['current_cover_image'], current_cover_image, state);
|
||||
|
||||
export const NODE_HANDLERS = {
|
||||
[NODE_ACTIONS.SET]: setData,
|
||||
[NODE_ACTIONS.SET_SAVE_ERRORS]: setSaveErrors,
|
||||
[NODE_ACTIONS.SET_LOADING]: setLoading,
|
||||
[NODE_ACTIONS.SET_LOADING_COMMENTS]: setLoadingComments,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { takeLatest, call, put, select, delay, all } from 'redux-saga/effects';
|
||||
import { push } from 'connected-react-router';
|
||||
import omit from 'ramda/es/omit';
|
||||
|
||||
import { NODE_ACTIONS, EMPTY_NODE, EMPTY_COMMENT, NODE_EDITOR_DATA } from './constants';
|
||||
import {
|
||||
|
@ -23,6 +24,8 @@ import {
|
|||
nodeGotoNode,
|
||||
nodeLock,
|
||||
nodeLockComment,
|
||||
nodeEditComment,
|
||||
nodeSet,
|
||||
} from './actions';
|
||||
import {
|
||||
postNode,
|
||||
|
@ -168,14 +171,23 @@ function* onPostComment({ id, is_before }: ReturnType<typeof nodePostComment>) {
|
|||
const { current: current_node } = yield select(selectNode);
|
||||
|
||||
if (current_node && current_node.id === current.id) {
|
||||
// if user still browsing that node
|
||||
const { comments } = yield select(selectNode);
|
||||
yield put(nodeSetCommentData(0, { ...EMPTY_COMMENT }));
|
||||
const { comments, comment_data } = yield select(selectNode);
|
||||
|
||||
if (is_before) {
|
||||
yield put(nodeSetComments([comment, ...comments]));
|
||||
if (id === 0) {
|
||||
yield put(nodeSetCommentData(0, { ...EMPTY_COMMENT }));
|
||||
|
||||
if (is_before) {
|
||||
yield put(nodeSetComments([comment, ...comments]));
|
||||
} else {
|
||||
yield put(nodeSetComments([...comments, comment]));
|
||||
}
|
||||
} else {
|
||||
yield put(nodeSetComments([...comments, comment]));
|
||||
yield put(
|
||||
nodeSet({
|
||||
comment_data: omit([id.toString()], comment_data),
|
||||
comments: comments.map(item => (item.id === id ? comment : item)),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,6 +291,16 @@ function* onLockCommentSaga({ id, is_locked }: ReturnType<typeof nodeLockComment
|
|||
yield call(reqWrapper, postNodeLockComment, { current: current.id, id, is_locked });
|
||||
}
|
||||
|
||||
function* onEditCommentSaga({ id }: ReturnType<typeof nodeEditComment>) {
|
||||
const { comments } = yield select(selectNode);
|
||||
|
||||
const comment = comments.find(item => item.id === id);
|
||||
|
||||
if (!comment) return;
|
||||
|
||||
yield put(nodeSetCommentData(id, { ...EMPTY_COMMENT, ...comment }));
|
||||
}
|
||||
|
||||
export default function* nodeSaga() {
|
||||
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
|
||||
yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto);
|
||||
|
@ -291,4 +313,5 @@ export default function* nodeSaga() {
|
|||
yield takeLatest(NODE_ACTIONS.STAR, onStarSaga);
|
||||
yield takeLatest(NODE_ACTIONS.LOCK, onLockSaga);
|
||||
yield takeLatest(NODE_ACTIONS.LOCK_COMMENT, onLockCommentSaga);
|
||||
yield takeLatest(NODE_ACTIONS.EDIT_COMMENT, onEditCommentSaga);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue