diff --git a/src/redux/node/sagas.ts b/src/redux/node/sagas.ts index 309426d9..edabcc41 100644 --- a/src/redux/node/sagas.ts +++ b/src/redux/node/sagas.ts @@ -46,12 +46,13 @@ import { modalSetShown, modalShowDialog } from '../modal/actions'; import { selectFlow, selectFlowNodes } from '../flow/selectors'; import { URLS } from '~/constants/urls'; import { selectNode } from './selectors'; -import { Unwrap } from '../types'; +import { INode, Unwrap } from '../types'; import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs'; import { DIALOGS } from '~/redux/modal/constants'; import { has } from 'ramda'; import { selectLabListNodes } from '~/redux/lab/selectors'; import { labSetList } from '~/redux/lab/actions'; +import { INodeRelated } from '~/redux/node/types'; export function* updateNodeEverywhere(node) { const { @@ -152,6 +153,33 @@ 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( + apiGetNodeComments, + { + id: id!, + take: COMMENTS_DISPLAY, + skip: 0, + } + ); + + yield put( + nodeSet({ + comments, + comment_count, + }) + ); + } catch {} +} + function* onNodeLoad({ id }: ReturnType) { // Get node body try { @@ -169,19 +197,10 @@ function* onNodeLoad({ id }: ReturnType) { // Comments and related try { - const [{ comments, comment_count }, { related }]: [ - Unwrap, - Unwrap - ] = yield all([ - call(apiGetNodeComments, { id, take: COMMENTS_DISPLAY, skip: 0 }), - call(apiGetNodeRelated, { id }), - ]); + yield all([call(nodeGetComments, id), call(nodeGetRelated, id)]); yield put( nodeSet({ - comments, - comment_count, - related, is_loading_comments: false, }) ); @@ -223,6 +242,7 @@ 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 {} } diff --git a/src/redux/types.ts b/src/redux/types.ts index f78309a3..c13d6bdd 100644 --- a/src/redux/types.ts +++ b/src/redux/types.ts @@ -2,6 +2,8 @@ import { DetailedHTMLProps, InputHTMLAttributes, ReactElement } from 'react'; import { DIALOGS } from '~/redux/modal/constants'; import { ERRORS } from '~/constants/errors'; import { IUser } from './auth/types'; +import { CallEffect } from 'redux-saga/effects'; +import { AxiosResponse } from 'axios'; export interface ITag { id: number; @@ -200,6 +202,10 @@ export type Unwrap = T extends (...args: any) => Promise : T : T extends () => Iterator ? U + : T extends (...args: any) => Generator>> + ? U + : T extends (...args: any) => Generator> + ? U : any; export interface IEmbed {