From cf9e64ebd5e5808ae774399799655d903bc95e0b Mon Sep 17 00:00:00 2001 From: rdmclin2 Date: Sun, 14 Jul 2024 22:43:51 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E4=B8=8B=E8=BD=BD=E5=92=8C=E5=88=A0=E9=99=A4=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=97=B6=E7=9A=84=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/Actions/Agent.tsx | 1 - src/features/Actions/UnSubscribeButton.tsx | 30 --------- .../MarketInfo/actions/ChatButton.tsx | 35 +++++++++++ .../Subscribe.tsx} | 25 +++----- .../MarketInfo/actions/UnSubscribe.tsx | 43 +++++++++++++ src/features/MarketInfo/index.tsx | 36 +++-------- src/features/RoleInfo/index.tsx | 62 ------------------- src/features/RoleList/List/Item/Actions.tsx | 10 ++- .../SessionList/List/Item/Actions.tsx | 6 +- src/store/session/index.ts | 4 +- 10 files changed, 107 insertions(+), 145 deletions(-) delete mode 100644 src/features/Actions/UnSubscribeButton.tsx create mode 100644 src/features/MarketInfo/actions/ChatButton.tsx rename src/features/MarketInfo/{SubscribeButton.tsx => actions/Subscribe.tsx} (68%) create mode 100644 src/features/MarketInfo/actions/UnSubscribe.tsx delete mode 100644 src/features/RoleInfo/index.tsx diff --git a/src/features/Actions/Agent.tsx b/src/features/Actions/Agent.tsx index 64240f02..1c705fb8 100644 --- a/src/features/Actions/Agent.tsx +++ b/src/features/Actions/Agent.tsx @@ -50,7 +50,6 @@ const ThemeButton = memo(() => { overlayInnerStyle={{ padding: 0, }} - trigger={['click']} > diff --git a/src/features/Actions/UnSubscribeButton.tsx b/src/features/Actions/UnSubscribeButton.tsx deleted file mode 100644 index ec47e214..00000000 --- a/src/features/Actions/UnSubscribeButton.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Button, Popconfirm } from 'antd'; -import React from 'react'; -import { useTranslation } from 'react-i18next'; - -import { agentSelectors, useAgentStore } from '@/store/agent'; -import { useSessionStore } from '@/store/session'; - -export default () => { - const currentAgent = useAgentStore((s) => agentSelectors.currentAgentItem(s)); - const removeLocalAgent = useAgentStore((s) => s.removeLocalAgent); - const removeSession = useSessionStore((s) => s.removeSession); - const { t } = useTranslation(['common', 'role']); - - return ( - { - if (!currentAgent) return; - removeLocalAgent(currentAgent.agentId); - removeSession(currentAgent.agentId); - }} - title={t('actions.unsubscribe') + '?'} - > - - - ); -}; diff --git a/src/features/MarketInfo/actions/ChatButton.tsx b/src/features/MarketInfo/actions/ChatButton.tsx new file mode 100644 index 00000000..0da55e4d --- /dev/null +++ b/src/features/MarketInfo/actions/ChatButton.tsx @@ -0,0 +1,35 @@ +import { Button } from 'antd'; +import { useRouter } from 'next/navigation'; +import React, { memo } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { useGlobalStore } from '@/store/global'; +import { useSessionStore } from '@/store/session'; +import { Agent } from '@/types/agent'; + +interface ChatButtonProps { + agent: Agent; +} + +const ChatButton = memo(({ agent }) => { + const router = useRouter(); + const { t } = useTranslation('chat'); + const createSession = useSessionStore((s) => s.createSession); + + const [closePanel] = useGlobalStore((s) => [s.closePanel]); + return ( + + ); +}); + +export default ChatButton; diff --git a/src/features/MarketInfo/SubscribeButton.tsx b/src/features/MarketInfo/actions/Subscribe.tsx similarity index 68% rename from src/features/MarketInfo/SubscribeButton.tsx rename to src/features/MarketInfo/actions/Subscribe.tsx index f84aaabf..d4519d34 100644 --- a/src/features/MarketInfo/SubscribeButton.tsx +++ b/src/features/MarketInfo/actions/Subscribe.tsx @@ -1,4 +1,4 @@ -import { Button, Popover, Progress, Space, message } from 'antd'; +import { Button, Popover, Progress, Space } from 'antd'; import React, { memo } from 'react'; import { useTranslation } from 'react-i18next'; import { Flexbox } from 'react-layout-kit'; @@ -11,16 +11,11 @@ interface SubscribeButtonProps { agent: Agent; } -const SubscribeButton = memo((props: SubscribeButtonProps) => { - const [removeLocalAgent, subscribed] = useAgentStore((s) => [ - s.removeLocalAgent, - agentSelectors.subscribed(s), - ]); - - const { fetchAgentData, percent, downloading } = useDownloadAgent(); - +const Subscribe = memo((props: SubscribeButtonProps) => { const { agent } = props; + const subscribed = useAgentStore((s) => agentSelectors.subscribed(s)); + const { fetchAgentData, percent, downloading } = useDownloadAgent(); const isSubscribed = subscribed(agent.agentId); const { t } = useTranslation('common'); @@ -49,20 +44,14 @@ const SubscribeButton = memo((props: SubscribeButtonProps) => { key={'subscribe'} disabled={downloading} onClick={async () => { - if (isSubscribed) { - removeLocalAgent(agent.agentId).then(() => { - message.success(t('actions.unsubscribeSuccess')); - }); - } else { - await fetchAgentData(agent); - } + await fetchAgentData(agent); }} type={isSubscribed ? 'default' : 'primary'} > - {isSubscribed ? t('actions.unsubscribe') : t('actions.downloadSubscribe')} + {t('actions.downloadSubscribe')} ); }); -export default SubscribeButton; +export default Subscribe; diff --git a/src/features/MarketInfo/actions/UnSubscribe.tsx b/src/features/MarketInfo/actions/UnSubscribe.tsx new file mode 100644 index 00000000..28f1a61d --- /dev/null +++ b/src/features/MarketInfo/actions/UnSubscribe.tsx @@ -0,0 +1,43 @@ +import { Button, Popconfirm, message } from 'antd'; +import React, { memo, useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { useAgentStore } from '@/store/agent'; +import { useSessionStore } from '@/store/session'; +import { Agent } from '@/types/agent'; + +interface UnSubscribeButtonProps { + agent: Agent; +} + +const UnSubscribe = memo((props: UnSubscribeButtonProps) => { + const { agent } = props; + const removeLocalAgent = useAgentStore((s) => s.removeLocalAgent); + const removeSessionByAgentId = useSessionStore((s) => s.removeSessionByAgentId); + const [loading, setLoading] = useState(false); + + const { t } = useTranslation(['common', 'role']); + + return ( + { + if (!agent) return; + setLoading(true); + await removeLocalAgent(agent.agentId); + removeSessionByAgentId(agent.agentId); + setLoading(false); + message.success(t('actions.unsubscribeSuccess')); + }} + title={t('actions.unsubscribe') + '?'} + > + + + ); +}); + +export default UnSubscribe; diff --git a/src/features/MarketInfo/index.tsx b/src/features/MarketInfo/index.tsx index 0de19114..ccf0e725 100644 --- a/src/features/MarketInfo/index.tsx +++ b/src/features/MarketInfo/index.tsx @@ -1,19 +1,17 @@ import { DraggablePanel } from '@lobehub/ui'; -import { Button } from 'antd'; import { createStyles } from 'antd-style'; -import { useRouter } from 'next/navigation'; import React, { memo, useState } from 'react'; -import { useTranslation } from 'react-i18next'; import Author from '@/components/Author'; import AgentCard from '@/components/agent/AgentCard'; import SystemRole from '@/components/agent/SystemRole'; import { SIDEBAR_MAX_WIDTH, SIDEBAR_WIDTH } from '@/constants/token'; -import SubscribeButton from '@/features/MarketInfo/SubscribeButton'; import { agentSelectors, useAgentStore } from '@/store/agent'; -import { useGlobalStore } from '@/store/global'; import { marketStoreSelectors, useMarketStore } from '@/store/market'; -import { useSessionStore } from '@/store/session'; + +import ChatButton from './actions/ChatButton'; +import Subscribe from './actions/Subscribe'; +import UnSubscribe from './actions/UnSubscribe'; const useStyles = createStyles(({ css, token }) => ({ content: css` @@ -29,8 +27,6 @@ const useStyles = createStyles(({ css, token }) => ({ const Header = () => { const { styles } = useStyles(); - const router = useRouter(); - const { t } = useTranslation('chat'); const [tempId, setTempId] = useState(''); const [showAgentSidebar, activateAgent, deactivateAgent, currentAgentItem] = useMarketStore( (s) => [ @@ -40,34 +36,22 @@ const Header = () => { marketStoreSelectors.currentAgentItem(s), ], ); - const [closePanel] = useGlobalStore((s) => [s.closePanel]); const [subscribed] = useAgentStore((s) => [agentSelectors.subscribed(s)]); - const createSession = useSessionStore((s) => s.createSession); - const actions = []; if (currentAgentItem) { const isSubscribed = subscribed(currentAgentItem.agentId); if (isSubscribed) { actions.push( - , + , + , + ); + } else { + actions.push( + , ); } - - actions.push( - , - ); } return ( diff --git a/src/features/RoleInfo/index.tsx b/src/features/RoleInfo/index.tsx deleted file mode 100644 index 66a2ed26..00000000 --- a/src/features/RoleInfo/index.tsx +++ /dev/null @@ -1,62 +0,0 @@ -'use client'; - -import { DraggablePanel } from '@lobehub/ui'; -import { createStyles } from 'antd-style'; -import React, { memo, useState } from 'react'; - -import AgentCard from '@/components/agent/AgentCard'; -import SystemRole from '@/components/agent/SystemRole'; -import { SIDEBAR_MAX_WIDTH, SIDEBAR_WIDTH } from '@/constants/token'; -import Chat from '@/features/Actions/Chat'; -import UnSubscribeButton from '@/features/Actions/UnSubscribeButton'; -import { agentSelectors, useAgentStore } from '@/store/agent'; - -const useStyles = createStyles(({ css, token }) => ({ - content: css` - display: flex; - flex-direction: column; - height: 100% !important; - `, - header: css` - border-bottom: 1px solid ${token.colorBorder}; - `, -})); - -const Header = () => { - const { styles } = useStyles(); - const [tempId, setTempId] = useState(''); - const [showAgentSidebar, activateAgent, deactivateAgent] = useAgentStore((s) => [ - agentSelectors.showSideBar(s), - s.activateAgent, - s.deactivateAgent, - ]); - const currentAgent = useAgentStore((s) => agentSelectors.currentAgentItem(s)); - - return ( - { - if (!show) { - setTempId(useAgentStore.getState().currentIdentifier); - deactivateAgent(); - } else if (tempId) { - activateAgent(tempId); - } - }} - placement={'right'} - > - , ]} - agent={currentAgent} - footer={} - /> - - ); -}; - -export default memo(Header); diff --git a/src/features/RoleList/List/Item/Actions.tsx b/src/features/RoleList/List/Item/Actions.tsx index 1c46698e..67b88cc2 100644 --- a/src/features/RoleList/List/Item/Actions.tsx +++ b/src/features/RoleList/List/Item/Actions.tsx @@ -19,7 +19,10 @@ export default (props: ActionsProps) => { const { t } = useTranslation('common'); const [removeLocalAgent] = useAgentStore((s) => [s.removeLocalAgent]); const currentAgent = useAgentStore((s) => s.getAgentById(id)); - const createSession = useSessionStore((s) => s.createSession); + const [createSession, removeSessionByAgentId] = useSessionStore((s) => [ + s.createSession, + s.removeSessionByAgentId, + ]); const items: MenuProps['items'] = [ { @@ -43,8 +46,9 @@ export default (props: ActionsProps) => { modal.confirm({ centered: true, okButtonProps: { danger: true }, - onOk: () => { - removeLocalAgent(id); + async onOk() { + await removeLocalAgent(id); + removeSessionByAgentId(id); }, okText: t('actions.del'), cancelText: t('cancel'), diff --git a/src/features/SessionList/List/Item/Actions.tsx b/src/features/SessionList/List/Item/Actions.tsx index e6a652d3..ea0a0af4 100644 --- a/src/features/SessionList/List/Item/Actions.tsx +++ b/src/features/SessionList/List/Item/Actions.tsx @@ -14,7 +14,7 @@ export default (props: ActionsProps) => { const { id, setOpen } = props; const { modal } = App.useApp(); const { t } = useTranslation('common'); - const [removeSession] = useSessionStore((s) => [s.removeSession]); + const [removeSessionByAgentId] = useSessionStore((s) => [s.removeSessionByAgentId]); const items: MenuProps['items'] = [ { @@ -27,8 +27,8 @@ export default (props: ActionsProps) => { modal.confirm({ centered: true, okButtonProps: { danger: true }, - onOk: () => { - removeSession(id); + async onOk() { + removeSessionByAgentId(id); }, okText: t('actions.del'), cancelText: t('cancel'), diff --git a/src/store/session/index.ts b/src/store/session/index.ts index bbfd3491..8c6823f2 100644 --- a/src/store/session/index.ts +++ b/src/store/session/index.ts @@ -97,7 +97,7 @@ export interface SessionStore { /** * 移除会话 */ - removeSession: (id: string) => void; + removeSessionByAgentId: (id: string) => void; /** * 发送消息 * @param message 消息内容 @@ -392,7 +392,7 @@ export const createSessionStore: StateCreator { + removeSessionByAgentId: (id) => { const { sessionList, activeId } = get(); const sessions = produce(sessionList, (draft) => {