Skip to content

Commit 19eea94

Browse files
committed
changer drop-container to the top of the chat
1 parent 5b25ba7 commit 19eea94

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

react/src/components/Chat/ChatCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
170170
styles: { chatCard: chatCardStyle, alert: alertStyle, ...chatCardStyles },
171171
} = useStyles();
172172
const formRef = useRef<FormInstance>(null);
173+
const dropContainerRef = useRef<HTMLDivElement>(null);
173174
const [fetchKey, updateFetchKey] = useUpdatableState('first');
174175
const [startTime, setStartTime] = useState<number | null>(null);
175176

@@ -270,6 +271,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
270271
setMessages={setMessages}
271272
/>
272273
}
274+
ref={dropContainerRef}
273275
>
274276
<CustomModelForm
275277
modelId={modelId}
@@ -304,6 +306,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
304306
stop={stop}
305307
append={append}
306308
isLoading={isLoading}
309+
dropContainerRef={dropContainerRef}
307310
/>
308311
</Card>
309312
);

react/src/components/Chat/ChatInput.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { createDataTransferFiles } from '../../helper';
22
import Flex from '../Flex';
3-
import ChatSender, { AttachmentChangeInfo } from './ChatSender';
3+
import ChatSender, {
4+
AttachmentChangeInfo,
5+
ChageAttachmentsProps,
6+
} from './ChatSender';
47
import { CreateMessage, Message } from '@ai-sdk/react';
58
import type { AttachmentsProps } from '@ant-design/x';
69
import { ChatRequestOptions } from 'ai';
@@ -21,7 +24,7 @@ interface ChatRequest {
2124
fetchOnClient?: boolean;
2225
}
2326

24-
interface ChatInputProps extends ChatRequest {
27+
interface ChatInputProps extends ChatRequest, ChageAttachmentsProps {
2528
sync: boolean;
2629
input: string;
2730
setInput: (input: string) => void;
@@ -40,6 +43,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
4043
stop,
4144
append,
4245
isLoading,
46+
dropContainerRef,
4347
}) => {
4448
const { token } = theme.useToken();
4549

@@ -52,7 +56,6 @@ const ChatInput: React.FC<ChatInputProps> = ({
5256

5357
const [isOpenAttachments, setIsOpenAttachments] = useState(false);
5458
const [files, setFiles] = useState<AttachmentsProps['items']>([]);
55-
const dropContainerRef = useRef<HTMLDivElement>(null);
5659

5760
const [synchronizedMessage, setSynchronizedMessage] = useAtom(
5861
synchronizedMessageState,
@@ -197,12 +200,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
197200

198201
return (
199202
<>
200-
<Flex
201-
style={ChatInputStyle}
202-
direction="column"
203-
align="center"
204-
ref={dropContainerRef}
205-
>
203+
<Flex style={ChatInputStyle} direction="column" align="center">
206204
<ChatSender
207205
placeholder="Say something..."
208206
autoFocus

react/src/components/Chat/ChatSender.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { isEmpty } from 'lodash';
1111
import { useEffect, useRef } from 'react';
1212
import { useTranslation } from 'react-i18next';
1313

14-
interface ChageAttachmentsProps extends AttachmentsProps {
14+
export interface ChageAttachmentsProps {
1515
dropContainerRef: React.RefObject<HTMLElement | null>;
1616
}
1717

18-
const ChatAttachments: React.FC<ChageAttachmentsProps> = ({
18+
const ChatAttachments: React.FC<ChageAttachmentsProps & AttachmentsProps> = ({
1919
items,
2020
onChange,
2121
dropContainerRef,
@@ -51,12 +51,13 @@ export type AttachmentChangeInfo = Parameters<
5151
NonNullable<UploadProps['onChange']>
5252
>[0];
5353

54-
interface ChatSenderProps extends Omit<SenderProps, 'onChange'> {
54+
interface ChatSenderProps
55+
extends Omit<SenderProps, 'onChange'>,
56+
ChageAttachmentsProps {
5557
loading?: boolean;
5658
autoFocus?: boolean;
5759
items?: Attachment[];
5860
openAttachment?: boolean;
59-
dropContainerRef: React.RefObject<HTMLDivElement | null>;
6061
onInputChange?: (value: string) => void;
6162
onInputSubmit?: () => void;
6263
onInputCancel?: () => void;

0 commit comments

Comments
 (0)