'use client'; import React, { useEffect, useMemo } from 'react' import { BsArrowLeft, BsArrowRight } from "react-icons/bs"; import Agent from './NodeType/Agent'; import Form from './NodeType/Form'; import Unsupport from './NodeType/Unsupport'; import * as R from 'ramda' import { curNodeAtom, curStepAtom, arrowStateAtom, cardInstantAtomFamily, cardInstantAtomsAtom } from '../store'; import { useAtom, useAtomValue } from 'jotai'; const NodeRender = () => { const [curStep, setCurStep] = useAtom(curStepAtom) const node = useAtomValue(curNodeAtom) const arrowState = useAtomValue(arrowStateAtom) const Comp = useMemo(() => { return R.cond([ [R.propEq('form_card', 'type'), R.always(Form)], [R.propEq('UserTask', 'type'), R.always(Agent)], [R.T, R.always(Unsupport)], ])(node) }, [node, node?.id]) const nodeName = useMemo(() => { return R.cond([ [R.propEq('form_card', 'type'), R.always('表单填写')], [R.propEq('UserTask', 'type'), R.pathOr('Unknown Agent', ['properties', 'item', 'assistantName'])], [R.T, R.always('Unknown')], ])(node) }, [node, node?.id]) // 动态注册当前节点的Atom,并将其放进一个atom集合的atom,方便后续格式化所有节点实例 const cardInstantAtom = cardInstantAtomFamily(node?.id) const [, dispatchCardInstantAtoms] = useAtom(cardInstantAtomsAtom) useEffect(() => { if (node?.id) { dispatchCardInstantAtoms({ [node.id]: cardInstantAtom }) } }, [cardInstantAtom]) const onNextStep = () => { setCurStep(prev => prev + 1) } const onPrevStep = () => { setCurStep(prev => prev - 1) } return (