Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor: replace antd Modal with base-ui Modal in FileEditor (#14054)

Innei5196203414cf
diff --git a/src/features/ChatInput/ActionBar/Knowledge/index.tsx b/src/features/ChatInput/ActionBar/Knowledge/index.tsx
index 1814580aeec..fbdc4aeb189 100644
--- a/src/features/ChatInput/ActionBar/Knowledge/index.tsx
+++ b/src/features/ChatInput/ActionBar/Knowledge/index.tsx
@@ -4,7 +4,7 @@ import { memo, Suspense, useState } from 'react';
import { useTranslation } from 'react-i18next';
import TipGuide from '@/components/TipGuide';
-import { AttachKnowledgeModal } from '@/features/LibraryModal';
+import { openAttachKnowledgeModal } from '@/features/LibraryModal';
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
import { useUserStore } from '@/store/user';
import { preferenceSelectors } from '@/store/user/selectors';
@@ -21,10 +21,9 @@ const Knowledge = memo(() => {
preferenceSelectors.showUploadFileInKnowledgeBaseTip(s),
s.updateGuideState,
]);
- const [modalOpen, setModalOpen] = useState(false);
const [updating, setUpdating] = useState(false);
- const items = useControls({ setModalOpen, setUpdating });
+ const items = useControls({ openAttachKnowledgeModal, setUpdating });
if (!enableKnowledgeBase) return null;
if (!enableKnowledge)
@@ -68,7 +67,6 @@ const Knowledge = memo(() => {
) : (
content
)}
- <AttachKnowledgeModal open={modalOpen} setOpen={setModalOpen} />
</Suspense>
);
});
diff --git a/src/features/ChatInput/ActionBar/Knowledge/useControls.tsx b/src/features/ChatInput/ActionBar/Knowledge/useControls.tsx
index 4701acf2587..7400c6f6588 100644
--- a/src/features/ChatInput/ActionBar/Knowledge/useControls.tsx
+++ b/src/features/ChatInput/ActionBar/Knowledge/useControls.tsx
@@ -13,10 +13,10 @@ import { useAgentId } from '../../hooks/useAgentId';
import CheckboxItem from '../components/CheckboxWithLoading';
export const useControls = ({
- setModalOpen,
+ openAttachKnowledgeModal,
setUpdating,
}: {
- setModalOpen: (open: boolean) => void;
+ openAttachKnowledgeModal: () => void;
setUpdating: (updating: boolean) => void;
}) => {
const { t } = useTranslation('chat');
@@ -85,7 +85,7 @@ export const useControls = ({
key: 'knowledge-base-store',
label: t('knowledgeBase.viewMore'),
onClick: () => {
- setModalOpen(true);
+ openAttachKnowledgeModal();
},
},
];
diff --git a/src/features/ChatInput/ActionBar/Upload/index.tsx b/src/features/ChatInput/ActionBar/Upload/index.tsx
index cdecac0c006..2904ec2f1c6 100644
--- a/src/features/ChatInput/ActionBar/Upload/index.tsx
+++ b/src/features/ChatInput/ActionBar/Upload/index.tsx
@@ -12,7 +12,7 @@ import { message } from '@/components/AntdStaticMethods';
import FileIcon from '@/components/FileIcon';
import RepoIcon from '@/components/LibIcon';
import TipGuide from '@/components/TipGuide';
-import { AttachKnowledgeModal } from '@/features/LibraryModal';
+import { openAttachKnowledgeModal } from '@/features/LibraryModal';
import { useModelSupportVision } from '@/hooks/useModelSupportVision';
import { useAgentStore } from '@/store/agent';
import { agentByIdSelectors } from '@/store/agent/selectors';
@@ -54,7 +54,6 @@ const FileUpload = memo(() => {
preferenceSelectors.showUploadFileInKnowledgeBaseTip(s),
s.updateGuideState,
]);
- const [modalOpen, setModalOpen] = useState(false);
const [dropdownOpen, setDropdownOpen] = useState(false);
const [updating, setUpdating] = useState(false);
@@ -225,7 +224,7 @@ const FileUpload = memo(() => {
key: 'knowledge-base-store',
label: t('knowledgeBase.viewMore'),
onClick: () => {
- setModalOpen(true);
+ openAttachKnowledgeModal();
},
},
);
@@ -269,7 +268,6 @@ const FileUpload = memo(() => {
) : (
content
)}
- <AttachKnowledgeModal open={modalOpen} setOpen={setModalOpen} />
</Suspense>
);
});
diff --git a/src/features/LibraryModal/AssignKnowledgeBase/index.tsx b/src/features/LibraryModal/AssignKnowledgeBase/index.tsx
index b75452f2b22..c0aaf7a11a7 100644
--- a/src/features/LibraryModal/AssignKnowledgeBase/index.tsx
+++ b/src/features/LibraryModal/AssignKnowledgeBase/index.tsx
@@ -1,39 +1,31 @@
-import { Flexbox, Modal } from '@lobehub/ui';
+import { Flexbox } from '@lobehub/ui';
+import { createModal, type ModalInstance } from '@lobehub/ui/base-ui';
+import { t } from 'i18next';
import { memo } from 'react';
-import { useTranslation } from 'react-i18next';
import { useServerConfigStore } from '@/store/serverConfig';
import List from './List';
-interface AttachKnowledgeModalProps {
- open?: boolean;
- setOpen: (open: boolean) => void;
-}
-
-export const AttachKnowledgeModal = memo<AttachKnowledgeModalProps>(({ setOpen, open }) => {
- const { t } = useTranslation('chat');
+const Content = memo(() => {
const mobile = useServerConfigStore((s) => s.isMobile);
return (
- <Modal
- allowFullscreen
- footer={null}
- open={open}
- styles={{ body: { overflow: 'hidden' } }}
- title={t('knowledgeBase.library.title')}
- width={600}
- onCancel={() => {
- setOpen(false);
- }}
+ <Flexbox
+ gap={mobile ? 8 : 16}
+ style={{ maxHeight: mobile ? '-webkit-fill-available' : 'inherit' }}
+ width={'100%'}
>
- <Flexbox
- gap={mobile ? 8 : 16}
- style={{ maxHeight: mobile ? '-webkit-fill-available' : 'inherit' }}
- width={'100%'}
- >
- <List />
- </Flexbox>
- </Modal>
+ <List />
+ </Flexbox>
);
});
+
+export const openAttachKnowledgeModal = (): ModalInstance =>
+ createModal({
+ content: <Content />,
+ footer: false,
+ styles: { content: { overflow: 'hidden' } },
+ title: t('knowledgeBase.library.title', { ns: 'chat' }),
+ width: 600,
+ });