Commit 31930159 authored by Joel's avatar Joel

feat: var assigner data logic

parent 6e2611c8
import { useCallback, useState } from 'react'
import produce from 'immer'
import useVarList from './use-var-list'
import type { VariableAssignerNodeType } from './types'
const useConfig = (initInputs: VariableAssignerNodeType) => {
const [inputs, setInputs] = useState<VariableAssignerNodeType>(initInputs)
const handleOutputTypeChange = useCallback((outputType: string) => {
const newInputs = produce(inputs, (draft) => {
draft.output_type = outputType
})
setInputs(newInputs)
}, [inputs, setInputs])
const { handleVarListChange, handleAddVariable } = useVarList({
inputs,
setInputs,
})
return {
inputs,
handleOutputTypeChange,
handleVarListChange,
handleAddVariable,
}
}
export default useConfig
import { useCallback } from 'react'
import produce from 'immer'
import type { VariableAssignerNodeType } from './types'
import type { Variable } from '@/app/components/workflow/types'
type Params = {
inputs: VariableAssignerNodeType
setInputs: (newInputs: VariableAssignerNodeType) => void
}
function useVarList({
inputs,
setInputs,
}: Params) {
const handleVarListChange = useCallback((newList: Variable[]) => {
const newInputs = produce(inputs, (draft: any) => {
draft.variables = newList
})
setInputs(newInputs)
}, [inputs, setInputs])
const handleAddVariable = useCallback(() => {
const newInputs = produce(inputs, (draft: any) => {
draft.variables.push([])
})
setInputs(newInputs)
}, [inputs, setInputs])
return {
handleVarListChange,
handleAddVariable,
}
}
export default useVarList
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment