split hooks

This commit is contained in:
StyleZhang
2024-03-13 11:53:21 +08:00
parent 64fa343d16
commit a55a7603dd
25 changed files with 586 additions and 491 deletions

View File

@ -17,7 +17,7 @@ export const useChat = (
) => {
const { t } = useTranslation()
const { notify } = useToastContext()
const run = useWorkflowRun()
const { handleRun } = useWorkflowRun()
const hasStopResponded = useRef(false)
const connversationId = useRef('')
const taskIdRef = useRef('')
@ -126,7 +126,7 @@ export const useChat = (
let hasSetResponseId = false
run(
handleRun(
params,
{
onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
@ -179,7 +179,7 @@ export const useChat = (
},
},
)
}, [run, handleResponding, handleUpdateChatList, notify, t, updateCurrentQA])
}, [handleRun, handleResponding, handleUpdateChatList, notify, t, updateCurrentQA])
return {
conversationId: connversationId.current,

View File

@ -7,10 +7,7 @@ import { useNodes } from 'reactflow'
import FormItem from '../nodes/_base/components/before-run-form/form-item'
import { BlockEnum } from '../types'
import { useStore } from '../store'
import {
useWorkflow,
useWorkflowRun,
} from '../hooks'
import { useWorkflowRun } from '../hooks'
import type { StartNodeType } from '../nodes/start/types'
import Button from '@/app/components/base/button'
@ -18,8 +15,10 @@ const InputsPanel = () => {
const { t } = useTranslation()
const nodes = useNodes<StartNodeType>()
const inputs = useStore(s => s.inputs)
const run = useWorkflowRun()
const { handleRunInit } = useWorkflow()
const {
handleRun,
handleRunSetting,
} = useWorkflowRun()
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
const variables = startNode?.data.variables || []
@ -34,10 +33,10 @@ const InputsPanel = () => {
useStore.setState({ showInputsPanel: false })
}, [])
const handleRun = () => {
const doRun = () => {
handleCancel()
handleRunInit()
run({ inputs })
handleRunSetting()
handleRun({ inputs })
}
return (
@ -72,7 +71,7 @@ const InputsPanel = () => {
<Button
type='primary'
className='py-0 w-[190px] h-8 rounded-lg text-[13px] font-medium'
onClick={handleRun}
onClick={doRun}
>
{t('workflow.singleRun.startRun')}
</Button>