1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

updating related on node tags

This commit is contained in:
Fedor Katurov 2021-09-28 12:34:30 +07:00
parent 1242c04587
commit 0a75feef8d
2 changed files with 37 additions and 11 deletions

View file

@ -46,12 +46,13 @@ import { modalSetShown, modalShowDialog } from '../modal/actions';
import { selectFlow, selectFlowNodes } from '../flow/selectors'; import { selectFlow, selectFlowNodes } from '../flow/selectors';
import { URLS } from '~/constants/urls'; import { URLS } from '~/constants/urls';
import { selectNode } from './selectors'; import { selectNode } from './selectors';
import { Unwrap } from '../types'; import { INode, Unwrap } from '../types';
import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs'; import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs';
import { DIALOGS } from '~/redux/modal/constants'; import { DIALOGS } from '~/redux/modal/constants';
import { has } from 'ramda'; import { has } from 'ramda';
import { selectLabListNodes } from '~/redux/lab/selectors'; import { selectLabListNodes } from '~/redux/lab/selectors';
import { labSetList } from '~/redux/lab/actions'; import { labSetList } from '~/redux/lab/actions';
import { INodeRelated } from '~/redux/node/types';
export function* updateNodeEverywhere(node) { export function* updateNodeEverywhere(node) {
const { const {
@ -152,6 +153,33 @@ function* onNodeLoadMoreComments() {
} catch (error) {} } 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(
apiGetNodeComments,
{
id: id!,
take: COMMENTS_DISPLAY,
skip: 0,
}
);
yield put(
nodeSet({
comments,
comment_count,
})
);
} catch {}
}
function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) { function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
// Get node body // Get node body
try { try {
@ -169,19 +197,10 @@ function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
// Comments and related // Comments and related
try { try {
const [{ comments, comment_count }, { related }]: [ yield all([call(nodeGetComments, id), call(nodeGetRelated, id)]);
Unwrap<typeof apiGetNodeComments>,
Unwrap<typeof apiGetNodeRelated>
] = yield all([
call(apiGetNodeComments, { id, take: COMMENTS_DISPLAY, skip: 0 }),
call(apiGetNodeRelated, { id }),
]);
yield put( yield put(
nodeSet({ nodeSet({
comments,
comment_count,
related,
is_loading_comments: false, is_loading_comments: false,
}) })
); );
@ -223,6 +242,7 @@ function* onUpdateTags({ id, tags }: ReturnType<typeof nodeUpdateTags>) {
const { current }: ReturnType<typeof selectNode> = yield select(selectNode); const { current }: ReturnType<typeof selectNode> = yield select(selectNode);
if (!node || !node.id || node.id !== current.id) return; if (!node || !node.id || node.id !== current.id) return;
yield put(nodeSetTags(node.tags)); yield put(nodeSetTags(node.tags));
yield call(nodeGetRelated, id);
} catch {} } catch {}
} }

View file

@ -2,6 +2,8 @@ import { DetailedHTMLProps, InputHTMLAttributes, ReactElement } from 'react';
import { DIALOGS } from '~/redux/modal/constants'; import { DIALOGS } from '~/redux/modal/constants';
import { ERRORS } from '~/constants/errors'; import { ERRORS } from '~/constants/errors';
import { IUser } from './auth/types'; import { IUser } from './auth/types';
import { CallEffect } from 'redux-saga/effects';
import { AxiosResponse } from 'axios';
export interface ITag { export interface ITag {
id: number; id: number;
@ -200,6 +202,10 @@ export type Unwrap<T> = T extends (...args: any) => Promise<any>
: T : T
: T extends () => Iterator<any, infer U, any> : T extends () => Iterator<any, infer U, any>
? U ? U
: T extends (...args: any) => Generator<CallEffect<AxiosResponse<infer U>>>
? U
: T extends (...args: any) => Generator<CallEffect<infer U>>
? U
: any; : any;
export interface IEmbed { export interface IEmbed {