From 68562b699f465095c15069b8c5d5a0904e22b107 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Thu, 9 Mar 2023 16:14:07 +0800 Subject: [PATCH] Fix: copy code triggers UI for all code blocks Fixes #24 --- src/components/Chat/ChatContent/ChatContent.tsx | 2 +- src/components/Chat/ChatContent/Message/MessageContent.tsx | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/Chat/ChatContent/ChatContent.tsx b/src/components/Chat/ChatContent/ChatContent.tsx index 4c95404..ae872f0 100644 --- a/src/components/Chat/ChatContent/ChatContent.tsx +++ b/src/components/Chat/ChatContent/ChatContent.tsx @@ -38,7 +38,7 @@ const ChatContent = () => { } }, [generating]); - const { handleSubmit, error } = useSubmit(); + const { error } = useSubmit(); return (
diff --git a/src/components/Chat/ChatContent/Message/MessageContent.tsx b/src/components/Chat/ChatContent/Message/MessageContent.tsx index 507fa26..b6f0eba 100644 --- a/src/components/Chat/ChatContent/Message/MessageContent.tsx +++ b/src/components/Chat/ChatContent/Message/MessageContent.tsx @@ -69,9 +69,7 @@ const ContentView = React.memo( messageIndex: number; }) => { const { handleSubmit } = useSubmit(); - const [isDelete, setIsDelete] = useState(false); - const [copied, setCopied] = useState(false); const currentChatIndex = useStore((state) => state.currentChatIndex); const setChats = useStore((state) => state.setChats); const lastMessageIndex = useStore((state) => @@ -121,8 +119,9 @@ const ContentView = React.memo( components={{ code({ node, inline, className, children, ...props }) { if (inline) return {children}; - let highlight; + const [copied, setCopied] = useState(false); + let highlight; const match = /language-(\w+)/.exec(className || ''); const lang = match && match[1]; const isMatch = lang && hljs.getLanguage(lang);