mirror of
https://github.com/langgenius/dify.git
synced 2026-04-08 17:27:19 +08:00
30 lines
836 B
TypeScript
30 lines
836 B
TypeScript
import { useCallback, useState } from 'react'
|
|
import produce from 'immer'
|
|
import type { StartNodeType } from './types'
|
|
import type { InputVar } from '@/app/components/workflow/types'
|
|
|
|
const useConfig = (initInputs: StartNodeType) => {
|
|
const [inputs, setInputs] = useState<StartNodeType>(initInputs)
|
|
|
|
const handleVarListChange = useCallback((newList: InputVar[]) => {
|
|
const newInputs = produce(inputs, (draft: any) => {
|
|
draft.variables = newList
|
|
})
|
|
setInputs(newInputs)
|
|
}, [inputs, setInputs])
|
|
|
|
const handleAddVariable = useCallback((payload: InputVar) => {
|
|
const newInputs = produce(inputs, (draft: any) => {
|
|
draft.variables.push(payload)
|
|
})
|
|
setInputs(newInputs)
|
|
}, [inputs, setInputs])
|
|
return {
|
|
inputs,
|
|
handleVarListChange,
|
|
handleAddVariable,
|
|
}
|
|
}
|
|
|
|
export default useConfig
|