hooks.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { useCallback } from 'react'
  2. import { generateNewNode } from '../utils'
  3. import { useWorkflowStore } from '../store'
  4. import type { NoteNodeType } from '../note-node/types'
  5. import { CUSTOM_NOTE_NODE } from '../note-node/constants'
  6. import { NoteTheme } from '../note-node/types'
  7. import { useAppContext } from '@/context/app-context'
  8. export const useOperator = () => {
  9. const workflowStore = useWorkflowStore()
  10. const { userProfile } = useAppContext()
  11. const handleAddNote = useCallback(() => {
  12. const { newNode } = generateNewNode({
  13. type: CUSTOM_NOTE_NODE,
  14. data: {
  15. title: '',
  16. desc: '',
  17. type: '' as any,
  18. text: '',
  19. theme: NoteTheme.blue,
  20. author: userProfile?.name || '',
  21. showAuthor: true,
  22. width: 240,
  23. height: 88,
  24. _isCandidate: true,
  25. } as NoteNodeType,
  26. position: {
  27. x: 0,
  28. y: 0,
  29. },
  30. })
  31. workflowStore.setState({
  32. candidateNode: newNode,
  33. })
  34. }, [workflowStore, userProfile])
  35. return {
  36. handleAddNote,
  37. }
  38. }