ASide.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use client'
  2. import React, { useEffect, useMemo } from 'react'
  3. import * as R from 'ramda'
  4. import { useAtom, useAtomValue } from 'jotai'
  5. import { asideInstantAtomFamily, asideInstantAtomsAtom, curNodeAtom } from '../store'
  6. import Agent from './ASideType/Agent'
  7. import Form from './ASideType/Form'
  8. import Unsupport from './ASideType/Unsupport'
  9. const ASide = () => {
  10. const node = useAtomValue(curNodeAtom)
  11. const Comp = useMemo(() => {
  12. return R.cond([
  13. [R.propEq('form_card', 'type'), R.always(Form)],
  14. [R.propEq('UserTask', 'type'), R.always(Agent)],
  15. [R.T, R.always(Unsupport)],
  16. ])(node)
  17. }, [node, node?.id])
  18. // 动态注册当前节点的Atom,并将其放进一个atom集合的atom,方便后续格式化所有节点实例
  19. const asideInstantAtom = asideInstantAtomFamily(node?.id)
  20. const [, dispatchAsideInstantAtoms] = useAtom(asideInstantAtomsAtom)
  21. useEffect(() => {
  22. if (node?.id) {
  23. dispatchAsideInstantAtoms({ [node.id]: asideInstantAtom })
  24. }
  25. }, [asideInstantAtom])
  26. return (
  27. <div className="shadow-xl rounded-box shrink-0 basis-[350px] p-2">
  28. <Comp key={node?.id} node={node} asideInstantAtom={asideInstantAtom}></Comp>
  29. </div>
  30. )
  31. }
  32. export default React.memo(React.forwardRef(ASide))