fix(ai-chat): update message container width for improved layout consistency
- Adjusted the width calculations in multiple components to use `--ai-chat-message-container-width` instead of the previous layout width. This change ensures a more consistent and responsive design across the AI chat interface. - Updated components including `AIChainOfThought`, `AIDisplayFlowPart`, `AIReasoningPart`, and others to reflect this new width calculation, enhancing the overall user experience. These modifications aim to streamline the layout and improve visual coherence in the chat interface. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
+2
-2
@@ -33,7 +33,7 @@ export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = React.memo(
|
||||
if (!groups || groups.length === 0) return null
|
||||
|
||||
return (
|
||||
<div className={cn("border-border min-w-0 max-w-full text-left", className)}>
|
||||
<div className={cn("border-border w-full min-w-0 text-left", className)}>
|
||||
<CollapseCssGroup>
|
||||
<CollapseCss
|
||||
ref={collapseRef}
|
||||
@@ -41,7 +41,7 @@ export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = React.memo(
|
||||
collapseId={collapseId}
|
||||
defaultOpen={!currentChainReasoningIsFinished}
|
||||
title={
|
||||
<div className="group flex h-6 min-w-0 flex-1 items-center py-0">
|
||||
<div className="group flex h-6 w-[calc(var(--ai-chat-message-container-width,65ch))] min-w-0 flex-1 items-center py-0">
|
||||
<div className="flex items-center gap-2 text-xs">
|
||||
<span className="text-text-secondary">
|
||||
{!currentChainReasoningIsFinished ? (
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ export const AIDisplayFlowPart = toolMemo(({ part }: { part: ToolWithState<any>
|
||||
}, [nodes, edges, colorMode, present])
|
||||
|
||||
return (
|
||||
<div className="group relative my-2 aspect-[4/3] w-[calc(var(--ai-chat-layout-width,65ch))] max-w-full overflow-hidden rounded-md">
|
||||
<div className="group relative my-2 aspect-[4/3] w-[calc(var(--ai-chat-message-container-width,65ch))] max-w-full overflow-hidden rounded-md">
|
||||
<ReactFlow
|
||||
colorMode={colorMode}
|
||||
nodes={nodes}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ export const AIReasoningPart: React.FC<AIReasoningPartProps> = React.memo(({ tex
|
||||
|
||||
return (
|
||||
<div className={cn("min-w-0 max-w-full text-left", className)}>
|
||||
<div className="w-[calc(var(--ai-chat-layout-width,65ch))] max-w-full" />
|
||||
<div className="w-[calc(var(--ai-chat-message-container-width,65ch))] max-w-full" />
|
||||
<div className="text-xs">
|
||||
<pre className="text-text-secondary bg-material-medium overflow-x-auto whitespace-pre-wrap rounded p-3 text-[11px] leading-relaxed">
|
||||
{text}
|
||||
|
||||
+18
-4
@@ -9,7 +9,7 @@ import { ErrorBoundary } from "@sentry/react"
|
||||
import type { EditorState, LexicalEditor } from "lexical"
|
||||
import { AnimatePresence } from "motion/react"
|
||||
import { nanoid } from "nanoid"
|
||||
import type { FC, Ref } from "react"
|
||||
import type { FC, RefObject } from "react"
|
||||
import { Suspense, use, useEffect, useLayoutEffect, useRef, useState } from "react"
|
||||
import { useEventCallback, useEventListener } from "usehooks-ts"
|
||||
|
||||
@@ -316,7 +316,7 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
|
||||
: undefined,
|
||||
}}
|
||||
>
|
||||
<Messages contentRef={messagesContentRef} />
|
||||
<Messages contentRef={messagesContentRef as RefObject<HTMLDivElement>} />
|
||||
|
||||
{(status === "submitted" || status === "streaming") && (
|
||||
<AIChatWaitingIndicator />
|
||||
@@ -385,11 +385,25 @@ export const ChatInterface = (props: ChatInterfaceProps) => (
|
||||
</ErrorBoundary>
|
||||
)
|
||||
|
||||
const Messages: FC<{ contentRef?: Ref<HTMLDivElement> }> = ({ contentRef }) => {
|
||||
const Messages: FC<{ contentRef?: RefObject<HTMLDivElement> }> = ({ contentRef }) => {
|
||||
const messages = useMessages()
|
||||
|
||||
const [messageContainerWidth, setMessageContainerWidth] = useState<number>(0)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!contentRef) return
|
||||
setMessageContainerWidth(contentRef.current?.clientWidth ?? 0)
|
||||
}, [contentRef])
|
||||
return (
|
||||
<div ref={contentRef} className="relative flex min-w-0 flex-1 flex-col">
|
||||
<div
|
||||
ref={contentRef}
|
||||
className="relative flex min-w-0 flex-1 flex-col"
|
||||
style={
|
||||
{
|
||||
"--ai-chat-message-container-width": `${messageContainerWidth}px`,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
{messages.map((message, index) => {
|
||||
const isLastMessage = index === messages.length - 1
|
||||
return (
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ export const AIMarkdownStreamingMessage = memo(
|
||||
const className = tw`prose max-w-full dark:prose-invert prose-sm
|
||||
prose-h1:text-2xl prose-h2:text-xl prose-h2:mt-2 prose-h3:text-lg prose-h4:text-base prose-h5:text-base prose-h6:text-sm
|
||||
prose-li:list-disc prose-li:marker:text-accent prose-hr:border-border prose-hr:mx-8
|
||||
w-[calc(var(--ai-chat-layout-width,65ch))]
|
||||
w-[calc(var(--ai-chat-message-container-width,65ch))]
|
||||
prose-pre:text-base
|
||||
`
|
||||
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ export const AIMessageParts: React.FC<AIMessagePartsProps> = React.memo(
|
||||
|
||||
case "tool-displayFlowChart": {
|
||||
const loadingElement = (
|
||||
<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="bg-material-medium my-2 flex aspect-[4/3] w-[calc(var(--ai-chat-message-container-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" />
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ export const ToolInvocationComponent: React.FC<ToolInvocationComponentProps> = R
|
||||
<div
|
||||
className={`min-w-0 max-w-full text-left ${hasError ? "border-red/30" : "border-border"}`}
|
||||
>
|
||||
<div className="w-[calc(var(--ai-chat-layout-width,65ch))] max-w-full" />
|
||||
<div className="w-[calc(var(--ai-chat-message-container-width,65ch))] max-w-full" />
|
||||
|
||||
<div className="w-full">
|
||||
<CollapseCssGroup>
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@ export const UserChatMessage: React.FC<UserChatMessageProps> = React.memo(({ mes
|
||||
exit={{ opacity: 0, scale: 0.98 }}
|
||||
transition={{ duration: 0.15, ease: "easeOut" }}
|
||||
>
|
||||
<div className="w-full max-w-[var(--ai-chat-layout-width,65ch)]">
|
||||
<div className="w-full max-w-[var(--ai-chat-message-container-width,65ch)]">
|
||||
<EditableMessage
|
||||
messageId={messageId}
|
||||
parts={message.parts}
|
||||
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @see https://github.com/Ephibbs/flowtoken/blob/main/src/components/AnimatedMarkdown.tsx
|
||||
*/
|
||||
import "./styles.css"
|
||||
|
||||
import type { LinkProps } from "@follow/components/ui/link/LinkWithTooltip.js"
|
||||
import { isBizId } from "@follow/utils"
|
||||
|
||||
Reference in New Issue
Block a user