mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
Set default active agent and session on load
- Automatically select first agent if none active after loading - Automatically select first session per agent if none active after loading - Prevent empty selection states in UI components
This commit is contained in:
parent
3ae1b3d4cb
commit
d960a42d6e
@ -5,7 +5,7 @@ import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setActiveAgentId as setActiveAgentIdAction } from '@renderer/store/runtime'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { FC, useCallback } from 'react'
|
||||
import { FC, useCallback, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import AgentItem from './components/AgentItem'
|
||||
@ -27,6 +27,12 @@ export const AgentsTab: FC<AssistantsTabProps> = () => {
|
||||
[dispatch]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && agents.length > 0 && !activeAgentId) {
|
||||
setActiveAgentId(agents[0].id)
|
||||
}
|
||||
}, [isLoading, agents, activeAgentId, setActiveAgentId])
|
||||
|
||||
return (
|
||||
<div className="agents-tab h-full w-full p-2">
|
||||
{isLoading && <Spinner />}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import { Button, Spinner } from '@heroui/react'
|
||||
import { SessionModal } from '@renderer/components/Popups/agent/SessionModal'
|
||||
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
||||
import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setActiveSessionIdAction, setActiveTopicOrSessionAction } from '@renderer/store/runtime'
|
||||
import { AnimatePresence,motion } from 'framer-motion'
|
||||
import { AnimatePresence, motion } from 'framer-motion'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { memo, useCallback } from 'react'
|
||||
import { memo, useCallback, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import SessionItem from './SessionItem'
|
||||
@ -19,6 +20,8 @@ interface SessionsProps {
|
||||
const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
||||
const { t } = useTranslation()
|
||||
const { sessions, isLoading, deleteSession } = useSessions(agentId)
|
||||
const { chat } = useRuntime()
|
||||
const { activeSessionId } = chat
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const setActiveSessionId = useCallback(
|
||||
@ -29,6 +32,14 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
||||
[dispatch]
|
||||
)
|
||||
|
||||
const currentActiveSessionId = activeSessionId[agentId]
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && sessions.length > 0 && !currentActiveSessionId) {
|
||||
setActiveSessionId(agentId, sessions[0].id)
|
||||
}
|
||||
}, [isLoading, sessions, currentActiveSessionId, agentId, setActiveSessionId])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<motion.div
|
||||
|
||||
Loading…
Reference in New Issue
Block a user