diff --git a/src/app/(main)/chat/(workspace)/_layout/useInitAgentConfig.ts b/src/app/(main)/chat/(workspace)/_layout/useInitAgentConfig.ts index 94c02ef07398..82b09953e3ae 100644 --- a/src/app/(main)/chat/(workspace)/_layout/useInitAgentConfig.ts +++ b/src/app/(main)/chat/(workspace)/_layout/useInitAgentConfig.ts @@ -1,30 +1,10 @@ -import { useEffect } from 'react'; - import { useAgentStore } from '@/store/agent'; -import { useChatStore } from '@/store/chat'; import { useSessionStore } from '@/store/session'; export const useInitAgentConfig = () => { const [useFetchAgentConfig] = useAgentStore((s) => [s.useFetchAgentConfig]); - const [switchTopic] = useChatStore((s) => [s.switchTopic]); const [sessionId] = useSessionStore((s) => [s.activeId]); - useEffect(() => { - // // when activeId changed, switch topic to undefined - const unsubscribe = useSessionStore.subscribe( - (s) => s.activeId, - (activeId) => { - switchTopic(); - - useAgentStore.setState({ activeId }, false, 'updateActiveId'); - }, - ); - - return () => { - unsubscribe(); - }; - }, []); - return useFetchAgentConfig(sessionId); }; diff --git a/src/app/(main)/chat/@session/features/SessionHydration.tsx b/src/app/(main)/chat/@session/features/SessionHydration.tsx index 37b716e04a4a..21b228e564ad 100644 --- a/src/app/(main)/chat/@session/features/SessionHydration.tsx +++ b/src/app/(main)/chat/@session/features/SessionHydration.tsx @@ -1,32 +1,35 @@ 'use client'; -import { useResponsive } from 'antd-style'; import { useQueryState } from 'nuqs'; import { parseAsString } from 'nuqs/server'; import { memo, useEffect } from 'react'; import { createStoreUpdater } from 'zustand-utils'; +import { useAgentStore } from '@/store/agent'; +import { useChatStore } from '@/store/chat'; import { useSessionStore } from '@/store/session'; // sync outside state to useSessionStore const SessionHydration = memo(() => { const useStoreUpdater = createStoreUpdater(useSessionStore); - - // TODO: 后面考虑可以删除了,用 useServerConfigStore 就不需要再这里注入了 - const { mobile } = useResponsive(); - useStoreUpdater('isMobile', mobile); + const useAgentStoreUpdater = createStoreUpdater(useAgentStore); + const [switchTopic] = useChatStore((s) => [s.switchTopic]); // two-way bindings the url and session store const [session, setSession] = useQueryState( 'session', - parseAsString.withDefault('inbox').withOptions({ history: 'replace', throttleMs: 500 }), + parseAsString.withDefault('inbox').withOptions({ history: 'replace', throttleMs: 50 }), ); useStoreUpdater('activeId', session); + useAgentStoreUpdater('activeId', session); useEffect(() => { const unsubscribe = useSessionStore.subscribe( (s) => s.activeId, - (state) => setSession(state), + (state) => { + switchTopic(); + setSession(state); + }, ); return () => { diff --git a/src/app/(main)/market/@detail/features/Header.tsx b/src/app/(main)/market/@detail/features/Header.tsx index cac436f3dfec..1d2fca76d6ab 100644 --- a/src/app/(main)/market/@detail/features/Header.tsx +++ b/src/app/(main)/market/@detail/features/Header.tsx @@ -3,7 +3,7 @@ import { App, Button, Typography } from 'antd'; import isEqual from 'fast-deep-equal'; import { startCase } from 'lodash-es'; import { useRouter } from 'next/navigation'; -import { memo } from 'react'; +import { memo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Center, Flexbox } from 'react-layout-kit'; @@ -23,7 +23,7 @@ const Header = memo(() => { const { styles } = useStyles(); const createSession = useSessionStore((s) => s.createSession); const agentItem = useMarketStore(agentMarketSelectors.currentAgentItem, isEqual); - + const [isLoading, setIsLoading] = useState(false); const { message } = App.useApp(); const { meta, createAt, author, homepage, config } = agentItem; @@ -34,15 +34,19 @@ const Header = memo(() => { const handleAddAgentAndConverse = async () => { if (!agentItem) return; + setIsLoading(true); const session = await createSession({ config, meta }); + setIsLoading(false); message.success(t('addAgentSuccess')); router.push(SESSION_CHAT_URL(session, isMobile)); }; - const handleAddAgent = () => { + const handleAddAgent = async () => { if (!agentItem) return; + setIsLoading(true); createSession({ config, meta }, false); message.success(t('addAgentSuccess')); + setIsLoading(false); }; return ( @@ -56,10 +60,10 @@ const Header = memo(() => { ))}
{description}
- - diff --git a/src/store/session/slices/session/action.test.ts b/src/store/session/slices/session/action.test.ts index b66076a55570..cbfd50471c0b 100644 --- a/src/store/session/slices/session/action.test.ts +++ b/src/store/session/slices/session/action.test.ts @@ -101,9 +101,6 @@ describe('SessionAction', () => { expect(call[1]).toMatchObject({ config: { displayMode: 'docs' } }); expect(createdSessionId).toBe(newSessionId); - expect(mockRouterPush).not.toHaveBeenCalledWith( - SESSION_CHAT_URL(newSessionId, result.current.isMobile), - ); }); }); diff --git a/src/store/session/slices/session/initialState.ts b/src/store/session/slices/session/initialState.ts index c97e589a9244..6f12f4cf6856 100644 --- a/src/store/session/slices/session/initialState.ts +++ b/src/store/session/slices/session/initialState.ts @@ -8,7 +8,6 @@ export interface SessionState { activeId: string; customSessionGroups: CustomSessionGroup[]; defaultSessions: LobeAgentSession[]; - isMobile?: boolean; isSearching: boolean; isSessionsFirstFetchFinished: boolean; pinnedSessions: LobeAgentSession[]; @@ -25,7 +24,6 @@ export const initialSessionState: SessionState = { activeId: 'inbox', customSessionGroups: [], defaultSessions: [], - isMobile: false, isSearching: false, isSessionsFirstFetchFinished: false, pinnedSessions: [],