fix(ai-chat): handle empty text in AIReasoningPart and improve message button visibility
- Added a check to return null if the text is empty in AIReasoningPart, preventing unnecessary rendering. - Replaced motion div with a standard div for action buttons in AIChatMessage, improving visibility on hover with a more straightforward opacity transition. - Updated loading element styling in AIMessageParts for better layout and visual consistency. These changes enhance the user experience by ensuring components render correctly and improving the visibility of interactive elements. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
+1
@@ -24,6 +24,7 @@ export const AIReasoningPart: React.FC<AIReasoningPartProps> = React.memo(
|
||||
setIsOpen(true)
|
||||
}
|
||||
}, [isStreaming])
|
||||
if (!text) return null
|
||||
|
||||
return (
|
||||
<div className={cn("border-border min-w-0 max-w-full text-left", className)}>
|
||||
|
||||
+3
-16
@@ -63,7 +63,6 @@ export const AIChatMessage: React.FC<AIChatMessageProps> = React.memo(({ message
|
||||
throw thenable
|
||||
}
|
||||
|
||||
const [isHovered, setIsHovered] = React.useState(false)
|
||||
const getMessageMarkdownFormat = useMessageMarkdownFormat(message)
|
||||
|
||||
const handleCopy = React.useCallback(async () => {
|
||||
@@ -77,12 +76,7 @@ export const AIChatMessage: React.FC<AIChatMessageProps> = React.memo(({ message
|
||||
}, [getMessageMarkdownFormat])
|
||||
|
||||
return (
|
||||
<div
|
||||
onContextMenu={stopPropagation}
|
||||
className="group flex justify-start"
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
>
|
||||
<div onContextMenu={stopPropagation} className="group flex justify-start">
|
||||
<div className="text-text relative flex max-w-full flex-col gap-2">
|
||||
{/* Normal message display */}
|
||||
<div className="text-text">
|
||||
@@ -92,14 +86,7 @@ export const AIChatMessage: React.FC<AIChatMessageProps> = React.memo(({ message
|
||||
</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
<m.div
|
||||
className="absolute bottom-1 left-0 flex gap-1"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{
|
||||
opacity: isHovered ? 1 : 0,
|
||||
}}
|
||||
transition={{ duration: 0.2, ease: "easeOut" }}
|
||||
>
|
||||
<div className="absolute -left-2 bottom-1 flex gap-1 opacity-0 transition-opacity duration-200 group-hover:opacity-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCopy}
|
||||
@@ -109,7 +96,7 @@ export const AIChatMessage: React.FC<AIChatMessageProps> = React.memo(({ message
|
||||
<i className="i-mgc-copy-2-cute-re size-3" />
|
||||
<span>Copy</span>
|
||||
</button>
|
||||
</m.div>
|
||||
</div>
|
||||
|
||||
<div className="h-6" />
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ export const AIMessageParts: React.FC<AIMessagePartsProps> = React.memo(({ messa
|
||||
|
||||
case "tool-displayFlowChart": {
|
||||
const loadingElement = (
|
||||
<div className="my-2 flex aspect-[4/3] w-[calc(var(--ai-chat-layout-width,65ch)-120px)] max-w-prose items-center justify-center">
|
||||
<div className="bg-material-medium my-2 flex aspect-[4/3] w-[calc(var(--ai-chat-layout-width,65ch))] max-w-full items-center justify-center rounded">
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<i className="i-mgc-loading-3-cute-re text-text-secondary size-4 animate-spin" />
|
||||
|
||||
Reference in New Issue
Block a user