Skip to content

Commit

Permalink
fix(delete-node): update the delete node logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanFarooqDev committed Apr 24, 2024
1 parent 540d5aa commit 8db9187
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/ModalsContainer/RemoveNodeModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useEffect, useState } from 'react'
import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { deleteNode } from '~/network/fetchSourcesData'
import { deleteNode, getTopicsData } from '~/network/fetchSourcesData'
import { useDataStore, useSelectedNode } from '~/stores/useDataStore'
import { useModal } from '~/stores/useModalStore'
import { NodeExtended } from '~/types'
import { NodeExtended, Topic } from '~/types'
import { colors } from '~/utils/colors'
import { TitleEditor } from '../Title'

Expand All @@ -19,12 +19,12 @@ export const Body = () => {
const { close: closeEditNodeModal } = useModal('editNodeName')

const [loading, setLoading] = useState(false)
const [removeNode, setSelectedNode, data] = useDataStore((s) => [s.removeNode, s.setSelectedNode, s.data])
const [removeNode, setSelectedNode] = useDataStore((s) => [s.removeNode, s.setSelectedNode])

const [topicIsLoading, setTopicIsLoading] = useState(false)

const [actualNode, setActualNode] = useState<null | NodeExtended>()
const [actualTopicNode, setActualTopicNode] = useState<null | NodeExtended>()
const [actualTopicNode, setActualTopicNode] = useState<null | Topic>()

const selectedNode = useSelectedNode()

Expand All @@ -42,7 +42,9 @@ export const Body = () => {

try {
if (selectedNode.type === 'topic') {
const node = data?.nodes.find((i: NodeExtended) => i.name === selectedNode.name)
const { data } = await getTopicsData({ search: selectedNode?.name })

const node = data.find((i: Topic) => i.name === selectedNode.name)

setActualTopicNode(node)
} else {
Expand All @@ -56,7 +58,7 @@ export const Body = () => {
}

init()
}, [selectedNode, data?.nodes])
}, [selectedNode])

const handleTopicRemove = async () => {
setLoading(true)
Expand Down Expand Up @@ -86,10 +88,12 @@ export const Body = () => {

setLoading(true)

const selectedNodeId = selectedNode?.ref_id as string

try {
await deleteNode(refId)

removeNode(refId)
removeNode(selectedNodeId)
setSelectedNode(null)

closeHandler()
Expand Down

0 comments on commit 8db9187

Please sign in to comment.