mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-05 20:41:30 +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 { useAppDispatch } from '@renderer/store'
|
||||||
import { setActiveAgentId as setActiveAgentIdAction } from '@renderer/store/runtime'
|
import { setActiveAgentId as setActiveAgentIdAction } from '@renderer/store/runtime'
|
||||||
import { Plus } from 'lucide-react'
|
import { Plus } from 'lucide-react'
|
||||||
import { FC, useCallback } from 'react'
|
import { FC, useCallback, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import AgentItem from './components/AgentItem'
|
import AgentItem from './components/AgentItem'
|
||||||
@ -27,6 +27,12 @@ export const AgentsTab: FC<AssistantsTabProps> = () => {
|
|||||||
[dispatch]
|
[dispatch]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && agents.length > 0 && !activeAgentId) {
|
||||||
|
setActiveAgentId(agents[0].id)
|
||||||
|
}
|
||||||
|
}, [isLoading, agents, activeAgentId, setActiveAgentId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="agents-tab h-full w-full p-2">
|
<div className="agents-tab h-full w-full p-2">
|
||||||
{isLoading && <Spinner />}
|
{isLoading && <Spinner />}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import { Button, Spinner } from '@heroui/react'
|
import { Button, Spinner } from '@heroui/react'
|
||||||
import { SessionModal } from '@renderer/components/Popups/agent/SessionModal'
|
import { SessionModal } from '@renderer/components/Popups/agent/SessionModal'
|
||||||
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
||||||
|
import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { setActiveSessionIdAction, setActiveTopicOrSessionAction } from '@renderer/store/runtime'
|
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 { Plus } from 'lucide-react'
|
||||||
import { memo, useCallback } from 'react'
|
import { memo, useCallback, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import SessionItem from './SessionItem'
|
import SessionItem from './SessionItem'
|
||||||
@ -19,6 +20,8 @@ interface SessionsProps {
|
|||||||
const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { sessions, isLoading, deleteSession } = useSessions(agentId)
|
const { sessions, isLoading, deleteSession } = useSessions(agentId)
|
||||||
|
const { chat } = useRuntime()
|
||||||
|
const { activeSessionId } = chat
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
const setActiveSessionId = useCallback(
|
const setActiveSessionId = useCallback(
|
||||||
@ -29,6 +32,14 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
|||||||
[dispatch]
|
[dispatch]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const currentActiveSessionId = activeSessionId[agentId]
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && sessions.length > 0 && !currentActiveSessionId) {
|
||||||
|
setActiveSessionId(agentId, sessions[0].id)
|
||||||
|
}
|
||||||
|
}, [isLoading, sessions, currentActiveSessionId, agentId, setActiveSessionId])
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user