From e8f8e3536d3816d9e9ac108d5d16a7e834a88b03 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Sun, 21 Nov 2021 17:15:44 +0700 Subject: [PATCH] removed node related from sagas and reducers --- src/pages/node/[id].tsx | 1 - src/redux/node/actions.ts | 5 ----- src/redux/node/handlers.ts | 23 +++++++++-------------- src/redux/node/reducer.ts | 8 +------- src/redux/node/sagas.ts | 18 +++--------------- src/redux/node/types.ts | 3 +-- src/utils/hooks/node/useFullNode.ts | 3 +-- 7 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/pages/node/[id].tsx b/src/pages/node/[id].tsx index 0ac92aa4..4b2d197a 100644 --- a/src/pages/node/[id].tsx +++ b/src/pages/node/[id].tsx @@ -26,7 +26,6 @@ const NodePage: FC = ({ isLoadingComments, comments, commentsCount, - related, lastSeenCurrent, } = useFullNode(id); diff --git a/src/redux/node/actions.ts b/src/redux/node/actions.ts index 44f36e96..b28e8cd9 100644 --- a/src/redux/node/actions.ts +++ b/src/redux/node/actions.ts @@ -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, diff --git a/src/redux/node/handlers.ts b/src/redux/node/handlers.ts index 503f82be..2bdd2da3 100644 --- a/src/redux/node/handlers.ts +++ b/src/redux/node/handlers.ts @@ -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) => assocPath(['comments'], comments, state); -const setRelated = (state: INodeState, { related }: ReturnType) => - assocPath(['related'], related, state); - const setTags = (state: INodeState, { tags }: ReturnType) => 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, diff --git a/src/redux/node/reducer.ts b/src/redux/node/reducer.ts index 5a9a4bea..21282a96 100644 --- a/src/redux/node/reducer.ts +++ b/src/redux/node/reducer.ts @@ -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, diff --git a/src/redux/node/sagas.ts b/src/redux/node/sagas.ts index eb8ea507..f366d1aa 100644 --- a/src/redux/node/sagas.ts +++ b/src/redux/node/sagas.ts @@ -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) { 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 = yield call(apiGetNodeRelated, { id }); - yield put(nodeSet({ related })); - } catch {} -} - function* nodeGetComments(id: INode['id']) { try { const { comments, comment_count }: Unwrap = yield call( @@ -188,9 +178,9 @@ function* onNodeLoad({ id }: ReturnType) { 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) { const { current }: ReturnType = 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) { try { const { tags }: Unwrap = yield call(apiDeleteNodeTag, { id, tagId }); yield put(nodeSetTags(tags)); - yield call(nodeGetRelated, id); } catch {} } diff --git a/src/redux/node/types.ts b/src/redux/node/types.ts index 33eaf80c..0f657755 100644 --- a/src/redux/node/types.ts +++ b/src/redux/node/types.ts @@ -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 = { diff --git a/src/utils/hooks/node/useFullNode.ts b/src/utils/hooks/node/useFullNode.ts index 09d8bfd4..2448e608 100644 --- a/src/utils/hooks/node/useFullNode.ts +++ b/src/utils/hooks/node/useFullNode.ts @@ -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 }; };