mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-04 11:49:02 +08:00
refactor(useAgents): simplify addAgent_ by accepting complete agent entity
This commit is contained in:
parent
e0d2d44f35
commit
943fccf655
@ -1,22 +1,17 @@
|
|||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { addAgent, removeAgent, setAgents, updateAgent } from '@renderer/store/agents'
|
import { addAgent, removeAgent, setAgents, updateAgent } from '@renderer/store/agents'
|
||||||
import { AgentEntity } from '@renderer/types'
|
import { AgentEntity } from '@renderer/types'
|
||||||
import { uuid } from '@renderer/utils'
|
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
export const useAgents = () => {
|
export const useAgents = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
/**
|
/**
|
||||||
* Adds a new agent to the store
|
* Adds a new agent to the store
|
||||||
* @param config - The configuration object for the new agent (without id)
|
* @param agent - The complete agent entity to add
|
||||||
*/
|
*/
|
||||||
const addAgent_ = useCallback(
|
const addAgent_ = useCallback(
|
||||||
(config: Omit<AgentEntity, 'id'>) => {
|
(agent: AgentEntity) => {
|
||||||
const entity = {
|
dispatch(addAgent(agent))
|
||||||
...config,
|
|
||||||
id: uuid()
|
|
||||||
} as const
|
|
||||||
dispatch(addAgent(entity))
|
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user