From 4aa3861b95d0a59a26878173009642f63d2b9a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Sat, 27 Jul 2024 12:30:50 +0300 Subject: [PATCH] fix: replaced topic with selected node --- .../MergeTopicModal/Title/index.tsx | 8 +-- .../ModalsContainer/MergeTopicModal/index.tsx | 53 +++++-------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/components/ModalsContainer/MergeTopicModal/Title/index.tsx b/src/components/ModalsContainer/MergeTopicModal/Title/index.tsx index e95d21950..f1bd12518 100644 --- a/src/components/ModalsContainer/MergeTopicModal/Title/index.tsx +++ b/src/components/ModalsContainer/MergeTopicModal/Title/index.tsx @@ -1,16 +1,16 @@ import { TextField } from '@mui/material' import { FC } from 'react' import styled from 'styled-components' -import { Flex } from '~/components/common/Flex' -import { Text } from '~/components/common/Text' import ArrowRight from '~/components/Icons/ArrowRight' import FlipIcon from '~/components/Icons/FlipIcon' import NodeCircleIcon from '~/components/Icons/NodeCircleIcon' -import { TEdge, Topic } from '~/types' +import { Flex } from '~/components/common/Flex' +import { Text } from '~/components/common/Text' +import { NodeExtended, TEdge } from '~/types' import { ToNode } from './ToNode' type Props = { - from: Topic + from: NodeExtended | undefined onSelect: (edge: TEdge | null) => void isSwapped: boolean setIsSwapped: () => void diff --git a/src/components/ModalsContainer/MergeTopicModal/index.tsx b/src/components/ModalsContainer/MergeTopicModal/index.tsx index a81c930f4..e7a44e5e9 100644 --- a/src/components/ModalsContainer/MergeTopicModal/index.tsx +++ b/src/components/ModalsContainer/MergeTopicModal/index.tsx @@ -4,12 +4,11 @@ import { FormProvider, useForm } from 'react-hook-form' import { ClipLoader } from 'react-spinners' import styled from 'styled-components' import { BaseModal } from '~/components/Modal' -import { Flex } from '~/components/common/Flex' -import { getTopicsData, postMergeTopics } from '~/network/fetchSourcesData' +import { postMergeTopics } from '~/network/fetchSourcesData' import { useSelectedNode } from '~/stores/useGraphStore' import { useModal } from '~/stores/useModalStore' import { useTopicsStore } from '~/stores/useTopicsStore' -import { TEdge, Topic } from '~/types' +import { NodeExtended, TEdge } from '~/types' import { colors } from '~/utils/colors' import { IS_ALIAS } from '../../SourcesTableModal/SourcesView/constants' import { TitleEditor } from './Title' @@ -25,36 +24,17 @@ export const MergeNodeModal = () => { const [loading, setLoading] = useState(false) const [isSwapped, setIsSwapped] = useState(false) const [selectedToNode, setSelectedToNode] = useState(null) - const [topicIsLoading, setTopicIsLoading] = useState(false) - const [topic, setTopic] = useState() + const [topic, setTopic] = useState() const selectedNode = useSelectedNode() useEffect(() => { - const init = async () => { - if (!selectedNode) { - return - } - - setTopicIsLoading(true) - - try { - if (selectedNode.type === 'topic') { - const response = await getTopicsData({ search: selectedNode?.name }) - - const node = response?.data.find((i: Topic) => i.name === selectedNode.name) - - setTopic(node) - } - } catch (error) { - console.log(error) - } finally { - setTopicIsLoading(false) - } + if (!selectedNode) { + return } - init() + setTopic(selectedNode) }, [selectedNode]) const closeHandler = () => { @@ -93,19 +73,14 @@ export const MergeNodeModal = () => { return ( - {topicIsLoading ? ( - - - - ) : ( - setIsSwapped(!isSwapped)} - /> - )} + setIsSwapped(!isSwapped)} + /> +