mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
#34 fixed boris layout with hooks
This commit is contained in:
parent
29e5aef01b
commit
62f0fa59ca
19 changed files with 231 additions and 773 deletions
|
@ -44,12 +44,6 @@ export const nodeSetCurrent = (current: INodeState['current']) => ({
|
|||
type: NODE_ACTIONS.SET_CURRENT,
|
||||
});
|
||||
|
||||
export const nodePostComment = (id: number, is_before: boolean) => ({
|
||||
id,
|
||||
is_before,
|
||||
type: NODE_ACTIONS.POST_COMMENT,
|
||||
});
|
||||
|
||||
export const nodePostLocalComment = (
|
||||
nodeId: INode['id'],
|
||||
comment: IComment,
|
||||
|
@ -58,7 +52,7 @@ export const nodePostLocalComment = (
|
|||
nodeId,
|
||||
comment,
|
||||
callback,
|
||||
type: NODE_ACTIONS.POST_LOCAL_COMMENT,
|
||||
type: NODE_ACTIONS.POST_COMMENT,
|
||||
});
|
||||
|
||||
export const nodeCancelCommentEdit = (id: number) => ({
|
||||
|
|
|
@ -41,8 +41,7 @@ export const NODE_ACTIONS = {
|
|||
SET_COMMENT_DATA: `${prefix}SET_COMMENT_DATA`,
|
||||
SET_EDITOR: `${prefix}SET_EDITOR`,
|
||||
|
||||
POST_COMMENT: `${prefix}POST_COMMENT`,
|
||||
POST_LOCAL_COMMENT: `${prefix}POST_LOCAL_COMMENT`,
|
||||
POST_COMMENT: `${prefix}POST_LOCAL_COMMENT`,
|
||||
SET_COMMENTS: `${prefix}SET_COMMENTS`,
|
||||
SET_RELATED: `${prefix}SET_RELATED`,
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import {
|
|||
nodeLoadNode,
|
||||
nodeLock,
|
||||
nodeLockComment,
|
||||
nodePostComment,
|
||||
nodePostLocalComment,
|
||||
nodeSave,
|
||||
nodeSet,
|
||||
|
@ -25,7 +24,6 @@ import {
|
|||
nodeSetLoadingComments,
|
||||
nodeSetRelated,
|
||||
nodeSetSaveErrors,
|
||||
nodeSetSendingComment,
|
||||
nodeSetTags,
|
||||
nodeUpdateTags
|
||||
} from './actions';
|
||||
|
@ -191,44 +189,7 @@ function* onNodeLoad({ id, order = 'ASC' }: ReturnType<typeof nodeLoadNode>) {
|
|||
return;
|
||||
}
|
||||
|
||||
function* onPostComment({ id }: ReturnType<typeof nodePostComment>) {
|
||||
const { current, comment_data } = yield select(selectNode);
|
||||
|
||||
yield put(nodeSetSendingComment(true));
|
||||
const {
|
||||
data: { comment },
|
||||
error,
|
||||
} = yield call(reqWrapper, postNodeComment, { data: comment_data[id], id: current.id });
|
||||
yield put(nodeSetSendingComment(false));
|
||||
|
||||
if (error || !comment) {
|
||||
return yield put(nodeSetCommentData(id, { error }));
|
||||
}
|
||||
|
||||
const { current: current_node } = yield select(selectNode);
|
||||
|
||||
if (current_node && current_node.id === current.id) {
|
||||
const { comments, comment_data: current_comment_data } = yield select(selectNode);
|
||||
|
||||
if (id === 0) {
|
||||
yield put(nodeSetCommentData(0, { ...EMPTY_COMMENT }));
|
||||
yield put(nodeSetComments([comment, ...comments]));
|
||||
} else {
|
||||
yield put(
|
||||
nodeSet({
|
||||
comment_data: omit([id.toString()], current_comment_data),
|
||||
comments: comments.map(item => (item.id === id ? comment : item)),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function* onPostLocalComment({
|
||||
nodeId,
|
||||
comment,
|
||||
callback,
|
||||
}: ReturnType<typeof nodePostLocalComment>) {
|
||||
function* onPostComment({ nodeId, comment, callback }: ReturnType<typeof nodePostLocalComment>) {
|
||||
const { data, error }: Unwrap<ReturnType<typeof postNodeComment>> = yield call(
|
||||
reqWrapper,
|
||||
postNodeComment,
|
||||
|
@ -390,7 +351,6 @@ export default function* nodeSaga() {
|
|||
yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto);
|
||||
yield takeLatest(NODE_ACTIONS.LOAD_NODE, onNodeLoad);
|
||||
yield takeLatest(NODE_ACTIONS.POST_COMMENT, onPostComment);
|
||||
yield takeLatest(NODE_ACTIONS.POST_LOCAL_COMMENT, onPostLocalComment);
|
||||
yield takeLatest(NODE_ACTIONS.CANCEL_COMMENT_EDIT, onCancelCommentEdit);
|
||||
yield takeLatest(NODE_ACTIONS.UPDATE_TAGS, onUpdateTags);
|
||||
yield takeLatest(NODE_ACTIONS.CREATE, onCreateSaga);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import { IState } from '../store';
|
||||
import { INodeState } from './reducer';
|
||||
import { IResultWithStatus, INode } from '../types';
|
||||
|
||||
export const selectNode = (state: IState): INodeState => state.node;
|
||||
|
||||
// export const catchNodeErrors = (data: IResultWithStatus<INode>): IResultWithStatus<INode> => ({
|
||||
// data,
|
||||
// errors: data.errors,
|
||||
// })
|
||||
export const selectNode = (state: IState) => state.node;
|
||||
export const selectNodeComments = (state: IState) => state.node.comments;
|
||||
export const selectNodeCurrent = (state: IState) => state.node.current;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue