From e2a69b2b2e40cb3acb11636763e1615ad2dd3087 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 22 Sep 2021 10:07:14 +0700 Subject: [PATCH] fixed lab node creation bug --- src/components/lab/LabNode/index.tsx | 2 +- src/redux/lab/types.ts | 2 +- src/redux/node/sagas.ts | 21 +++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/lab/LabNode/index.tsx b/src/components/lab/LabNode/index.tsx index 8572a4ee..ede99692 100644 --- a/src/components/lab/LabNode/index.tsx +++ b/src/components/lab/LabNode/index.tsx @@ -7,7 +7,7 @@ import { isAfter, parseISO } from 'date-fns'; interface IProps { node: INode; - lastSeen: string | null; + lastSeen: string | null | undefined; isLoading?: boolean; commentCount: number; } diff --git a/src/redux/lab/types.ts b/src/redux/lab/types.ts index 6d583042..7d3a8953 100644 --- a/src/redux/lab/types.ts +++ b/src/redux/lab/types.ts @@ -25,7 +25,7 @@ export type GetLabNodesRequest = { export interface ILabNode { node: INode; - last_seen: string | null; + last_seen: string | null | undefined; comment_count: number; } diff --git a/src/redux/node/sagas.ts b/src/redux/node/sagas.ts index 31ff9776..309426d9 100644 --- a/src/redux/node/sagas.ts +++ b/src/redux/node/sagas.ts @@ -50,6 +50,8 @@ import { 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'; export function* updateNodeEverywhere(node) { const { @@ -80,12 +82,19 @@ function* onNodeSubmitLocal({ node, callback }: ReturnType = yield select(selectFlowNodes); - const updated_flow_nodes = node.id - ? nodes.map(item => (item.id === result.id ? result : item)) - : [result, ...nodes]; - - yield put(flowSetNodes(updated_flow_nodes)); + if (node.is_promoted) { + const nodes: ReturnType = yield select(selectFlowNodes); + const updated_flow_nodes = node.id + ? nodes.map(item => (item.id === result.id ? result : item)) + : [result, ...nodes]; + yield put(flowSetNodes(updated_flow_nodes)); + } else { + const nodes: ReturnType = yield select(selectLabListNodes); + const updated_lab_nodes = node.id + ? nodes.map(item => (item.node.id === result.id ? { ...item, node: result } : item)) + : [{ node: result, comment_count: 0, last_seen: node.created_at }, ...nodes]; + yield put(labSetList({ nodes: updated_lab_nodes })); + } const { current } = yield select(selectNode);