mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
removed node related from sagas and reducers
This commit is contained in:
parent
d202a8cb18
commit
e8f8e3536d
7 changed files with 15 additions and 46 deletions
|
@ -26,7 +26,6 @@ const NodePage: FC<Props> = ({
|
|||
isLoadingComments,
|
||||
comments,
|
||||
commentsCount,
|
||||
related,
|
||||
lastSeenCurrent,
|
||||
} = useFullNode(id);
|
||||
|
||||
|
|
|
@ -69,11 +69,6 @@ export const nodeSetComments = (comments: IComment[]) => ({
|
|||
type: NODE_ACTIONS.SET_COMMENTS,
|
||||
});
|
||||
|
||||
export const nodeSetRelated = (related: INodeState['related']) => ({
|
||||
related,
|
||||
type: NODE_ACTIONS.SET_RELATED,
|
||||
});
|
||||
|
||||
export const nodeUpdateTags = (id: INode['id'], tags: string[]) => ({
|
||||
type: NODE_ACTIONS.UPDATE_TAGS,
|
||||
id,
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import { assocPath } from 'ramda';
|
||||
import { NODE_ACTIONS } from './constants';
|
||||
import {
|
||||
nodeSetSaveErrors,
|
||||
nodeSetLoading,
|
||||
nodeSetCurrent,
|
||||
nodeSetLoadingComments,
|
||||
nodeSetSendingComment,
|
||||
nodeSetComments,
|
||||
nodeSetTags,
|
||||
nodeSetEditor,
|
||||
nodeSetCoverImage,
|
||||
nodeSetRelated,
|
||||
nodeSet,
|
||||
nodeSetComments,
|
||||
nodeSetCoverImage,
|
||||
nodeSetCurrent,
|
||||
nodeSetEditor,
|
||||
nodeSetLoading,
|
||||
nodeSetLoadingComments,
|
||||
nodeSetSaveErrors,
|
||||
nodeSetSendingComment,
|
||||
nodeSetTags,
|
||||
} from './actions';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
|
@ -42,9 +41,6 @@ const setSendingComment = (
|
|||
const setComments = (state: INodeState, { comments }: ReturnType<typeof nodeSetComments>) =>
|
||||
assocPath(['comments'], comments, state);
|
||||
|
||||
const setRelated = (state: INodeState, { related }: ReturnType<typeof nodeSetRelated>) =>
|
||||
assocPath(['related'], related, state);
|
||||
|
||||
const setTags = (state: INodeState, { tags }: ReturnType<typeof nodeSetTags>) =>
|
||||
assocPath(['current', 'tags'], tags, state);
|
||||
|
||||
|
@ -64,7 +60,6 @@ export const NODE_HANDLERS = {
|
|||
[NODE_ACTIONS.SET_CURRENT]: setCurrent,
|
||||
[NODE_ACTIONS.SET_SENDING_COMMENT]: setSendingComment,
|
||||
[NODE_ACTIONS.SET_COMMENTS]: setComments,
|
||||
[NODE_ACTIONS.SET_RELATED]: setRelated,
|
||||
[NODE_ACTIONS.SET_TAGS]: setTags,
|
||||
[NODE_ACTIONS.SET_EDITOR]: setEditor,
|
||||
[NODE_ACTIONS.SET_COVER_IMAGE]: setCoverImage,
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
import { createReducer } from '~/utils/reducer';
|
||||
import { IComment, IFile, INode } from '../types';
|
||||
import { EMPTY_COMMENT, EMPTY_NODE } from './constants';
|
||||
import { EMPTY_NODE } from './constants';
|
||||
import { NODE_HANDLERS } from './handlers';
|
||||
import { INodeRelated } from '~/redux/node/types';
|
||||
|
||||
export type INodeState = Readonly<{
|
||||
editor: INode;
|
||||
current: INode;
|
||||
comments: IComment[];
|
||||
related: INodeRelated;
|
||||
lastSeenCurrent?: string;
|
||||
comment_count: number;
|
||||
current_cover_image?: IFile;
|
||||
|
@ -31,10 +29,6 @@ const INITIAL_STATE: INodeState = {
|
|||
current: { ...EMPTY_NODE },
|
||||
comment_count: 0,
|
||||
comments: [],
|
||||
related: {
|
||||
albums: {},
|
||||
similar: [],
|
||||
},
|
||||
current_cover_image: undefined,
|
||||
|
||||
is_loading: false,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { all, call, put, select, takeLatest, takeLeading } from 'redux-saga/effects';
|
||||
import { call, put, select, takeLatest, takeLeading } from 'redux-saga/effects';
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
import { COMMENTS_DISPLAY, EMPTY_NODE, NODE_ACTIONS, NODE_EDITOR_DATA } from './constants';
|
||||
|
@ -18,7 +18,6 @@ import {
|
|||
nodeSetEditor,
|
||||
nodeSetLoading,
|
||||
nodeSetLoadingComments,
|
||||
nodeSetRelated,
|
||||
nodeSetTags,
|
||||
nodeSubmitLocal,
|
||||
nodeUpdateTags,
|
||||
|
@ -27,7 +26,6 @@ import {
|
|||
apiDeleteNodeTag,
|
||||
apiGetNode,
|
||||
apiGetNodeComments,
|
||||
apiGetNodeRelated,
|
||||
apiLockComment,
|
||||
apiLockNode,
|
||||
apiPostComment,
|
||||
|
@ -111,7 +109,6 @@ function* onNodeGoto({ id, node_type }: ReturnType<typeof nodeGotoNode>) {
|
|||
if (node_type) yield put(nodeSetCurrent({ ...EMPTY_NODE, type: node_type }));
|
||||
|
||||
yield put(nodeLoadNode(id));
|
||||
yield put(nodeSetRelated({ albums: {}, similar: [] }));
|
||||
}
|
||||
|
||||
function* onNodeLoadMoreComments() {
|
||||
|
@ -146,13 +143,6 @@ function* onNodeLoadMoreComments() {
|
|||
} catch (error) {}
|
||||
}
|
||||
|
||||
function* nodeGetRelated(id: INode['id']) {
|
||||
try {
|
||||
const { related }: Unwrap<typeof apiGetNodeRelated> = yield call(apiGetNodeRelated, { id });
|
||||
yield put(nodeSet({ related }));
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function* nodeGetComments(id: INode['id']) {
|
||||
try {
|
||||
const { comments, comment_count }: Unwrap<typeof apiGetNodeComments> = yield call(
|
||||
|
@ -188,9 +178,9 @@ function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
|
|||
yield put(nodeSetLoading(false));
|
||||
}
|
||||
|
||||
// Comments and related
|
||||
// Comments
|
||||
try {
|
||||
yield all([call(nodeGetComments, id), call(nodeGetRelated, id)]);
|
||||
yield call(nodeGetComments, id);
|
||||
|
||||
yield put(
|
||||
nodeSet({
|
||||
|
@ -235,7 +225,6 @@ function* onUpdateTags({ id, tags }: ReturnType<typeof nodeUpdateTags>) {
|
|||
const { current }: ReturnType<typeof selectNode> = yield select(selectNode);
|
||||
if (!node || !node.id || node.id !== current.id) return;
|
||||
yield put(nodeSetTags(node.tags));
|
||||
yield call(nodeGetRelated, id);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
@ -243,7 +232,6 @@ function* onDeleteTag({ id, tagId }: ReturnType<typeof nodeDeleteTag>) {
|
|||
try {
|
||||
const { tags }: Unwrap<typeof apiDeleteNodeTag> = yield call(apiDeleteNodeTag, { id, tagId });
|
||||
yield put(nodeSetTags(tags));
|
||||
yield call(nodeGetRelated, id);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IComment, INode, ITag } from '~/redux/types';
|
||||
import { INodeState } from '~/redux/node/reducer';
|
||||
|
||||
export interface IEditorComponentProps {}
|
||||
|
||||
|
@ -37,7 +36,7 @@ export type ApiGetNodeRelatedRequest = {
|
|||
id: INode['id'];
|
||||
};
|
||||
export type ApiGetNodeRelatedResult = {
|
||||
related: INodeState['related'];
|
||||
related: INodeRelated;
|
||||
};
|
||||
|
||||
export type ApiPostCommentRequest = {
|
||||
|
|
|
@ -10,12 +10,11 @@ export const useFullNode = (id: string) => {
|
|||
comments,
|
||||
comment_count: commentsCount,
|
||||
is_loading_comments: isLoadingComments,
|
||||
related,
|
||||
lastSeenCurrent,
|
||||
} = useShallowSelect(selectNode);
|
||||
|
||||
useLoadNode(id);
|
||||
useOnNodeSeen(node);
|
||||
|
||||
return { node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments };
|
||||
return { node, comments, commentsCount, lastSeenCurrent, isLoading, isLoadingComments };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue