From 4060010bc34f5d0a69277d3983e610c3f8d664a9 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Fri, 5 Jul 2024 13:51:36 +0800 Subject: [PATCH] fix: default assistant topic id --- src/renderer/src/hooks/useAssistant.ts | 6 +++++- src/renderer/src/pages/home/HomePage.tsx | 6 +++++- src/renderer/src/pages/home/components/Assistants.tsx | 9 +++++---- src/renderer/src/pages/home/components/Navigation.tsx | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/hooks/useAssistant.ts b/src/renderer/src/hooks/useAssistant.ts index 0d7d8f39..5220e94c 100644 --- a/src/renderer/src/hooks/useAssistant.ts +++ b/src/renderer/src/hooks/useAssistant.ts @@ -1,3 +1,4 @@ +import { getDefaultTopic } from '@renderer/services/assistant' import { useAppDispatch, useAppSelector } from '@renderer/store' import { addTopic as _addTopic, @@ -53,7 +54,10 @@ export function useDefaultAssistant() { const dispatch = useAppDispatch() return { - defaultAssistant, + defaultAssistant: { + ...defaultAssistant, + topics: [getDefaultTopic()] + }, updateDefaultAssistant: (assistant: Assistant) => dispatch(_updateDefaultAssistant({ assistant })) } } diff --git a/src/renderer/src/pages/home/HomePage.tsx b/src/renderer/src/pages/home/HomePage.tsx index a3b82d74..2366f13f 100644 --- a/src/renderer/src/pages/home/HomePage.tsx +++ b/src/renderer/src/pages/home/HomePage.tsx @@ -39,7 +39,11 @@ const HomePage: FC = () => { - + diff --git a/src/renderer/src/pages/home/components/Assistants.tsx b/src/renderer/src/pages/home/components/Assistants.tsx index 307b40a8..947ffdb8 100644 --- a/src/renderer/src/pages/home/components/Assistants.tsx +++ b/src/renderer/src/pages/home/components/Assistants.tsx @@ -9,10 +9,11 @@ import { DeleteOutlined, EditOutlined } from '@ant-design/icons' interface Props { activeAssistant: Assistant - onActive: (assistant: Assistant) => void + setActiveAssistant: (assistant: Assistant) => void + onCreateAssistant: () => void } -const Assistants: FC = ({ activeAssistant, onActive }) => { +const Assistants: FC = ({ activeAssistant, setActiveAssistant, onCreateAssistant }) => { const { assistants, removeAssistant, updateAssistant } = useAssistants() const targetAssistant = useRef(null) @@ -20,7 +21,7 @@ const Assistants: FC = ({ activeAssistant, onActive }) => { removeAssistant(assistant.id) setTimeout(() => { const _assistant = last(assistants.filter((a) => a.id !== assistant.id)) - _assistant && onActive(_assistant) + _assistant ? setActiveAssistant(_assistant) : onCreateAssistant() }, 0) } @@ -57,7 +58,7 @@ const Assistants: FC = ({ activeAssistant, onActive }) => { trigger={['contextMenu']} onOpenChange={() => (targetAssistant.current = assistant)}> onActive(assistant)} + onClick={() => setActiveAssistant(assistant)} className={assistant.id === activeAssistant?.id ? 'active' : ''}> {assistant.name} {assistant.description} diff --git a/src/renderer/src/pages/home/components/Navigation.tsx b/src/renderer/src/pages/home/components/Navigation.tsx index 7244ebb9..e40239bf 100644 --- a/src/renderer/src/pages/home/components/Navigation.tsx +++ b/src/renderer/src/pages/home/components/Navigation.tsx @@ -10,7 +10,7 @@ interface Props { activeAssistant: Assistant } -const NavigationCenter: FC = ({ activeAssistant }) => { +const Navigation: FC = ({ activeAssistant }) => { const providers = useProviders() const { model, setModel } = useAssistant(activeAssistant.id) @@ -42,4 +42,4 @@ const DropdownMenu = styled(Dropdown)` margin-left: 10px; ` -export default NavigationCenter +export default Navigation