From 40ae4575a7f0dd05d3792542854f4c30b82e5f30 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sat, 23 Sep 2023 21:37:09 +0800 Subject: [PATCH] patch: fakePort `stop` --- src/components/ConversationCard/index.jsx | 5 ++--- src/components/ConversationItem/index.jsx | 4 +--- src/components/InputBox/index.jsx | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/ConversationCard/index.jsx b/src/components/ConversationCard/index.jsx index 32ccf4da..1f61950a 100644 --- a/src/components/ConversationCard/index.jsx +++ b/src/components/ConversationCard/index.jsx @@ -260,6 +260,7 @@ function ConversationCard(props) { const lastRecord = session.conversationRecords[session.conversationRecords.length - 1] if ( conversationItemData[conversationItemData.length - 1].done && + conversationItemData.length > 1 && lastRecord.question === conversationItemData[conversationItemData.length - 2].content ) { session.conversationRecords.pop() @@ -484,15 +485,13 @@ function ConversationCard(props) { key={idx} type={data.type} session={session} - done={data.done} - port={port} onRetry={idx === conversationItemData.length - 1 ? getRetryFn(session) : null} /> ))} { const newQuestion = new ConversationItemData('question', question) diff --git a/src/components/ConversationItem/index.jsx b/src/components/ConversationItem/index.jsx index af29248a..1709d727 100644 --- a/src/components/ConversationItem/index.jsx +++ b/src/components/ConversationItem/index.jsx @@ -9,7 +9,7 @@ import { isUsingCustomModel } from '../../config/index.mjs' import { useConfig } from '../../hooks/use-config.mjs' // eslint-disable-next-line -export function ConversationItem({ type, content, session, done, port, onRetry }) { +export function ConversationItem({ type, content, session, onRetry }) { const { t } = useTranslation() const [collapsed, setCollapsed] = useState(false) const config = useConfig() @@ -129,8 +129,6 @@ ConversationItem.propTypes = { type: PropTypes.oneOf(['question', 'answer', 'error']).isRequired, content: PropTypes.string.isRequired, session: PropTypes.object.isRequired, - done: PropTypes.bool.isRequired, - port: PropTypes.object.isRequired, onRetry: PropTypes.func, } diff --git a/src/components/InputBox/index.jsx b/src/components/InputBox/index.jsx index 87b7ae15..c0adcc9e 100644 --- a/src/components/InputBox/index.jsx +++ b/src/components/InputBox/index.jsx @@ -4,7 +4,7 @@ import { isFirefox, isMobile, isSafari, updateRefHeight } from '../../utils' import { useTranslation } from 'react-i18next' import { getUserConfig } from '../../config/index.mjs' -export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) { +export function InputBox({ onSubmit, enabled, postMessage, reverseResizeDir }) { const { t } = useTranslation() const [value, setValue] = useState('') const reverseDivRef = useRef(null) @@ -62,7 +62,7 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) { onSubmit(value) setValue('') } else { - port.postMessage({ stop: true }) + postMessage({ stop: true }) } } } @@ -117,7 +117,7 @@ InputBox.propTypes = { onSubmit: PropTypes.func.isRequired, enabled: PropTypes.bool.isRequired, reverseResizeDir: PropTypes.bool, - port: PropTypes.object.isRequired, + postMessage: PropTypes.func.isRequired, } export default InputBox