From 52d69dd55b07aa759a100061e16833ee023587f0 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Mon, 29 Jul 2024 17:22:11 +0800 Subject: [PATCH] file uploader --- .../base/chat/chat/chat-input-area/hooks.ts | 37 ++++++---- .../base/chat/chat/chat-input-area/index.tsx | 67 ++++++++++++------- .../chat/chat/chat-input-area/operation.tsx | 33 +++++++++ .../file-list-flex-operation.tsx | 27 ++++++++ .../file-list-flex/file-list-item.tsx | 31 +++++++++ .../file-list/file-list-flex/index.tsx | 9 --- .../file-list/file-list-full-width/index.tsx | 9 --- .../base/file-uploader/file-list/hooks.ts | 0 .../base/file-uploader/file-list/index.tsx | 0 .../components/base/file-uploader/index.ts | 1 + .../share/text-generation/run-once/index.tsx | 4 ++ 11 files changed, 162 insertions(+), 56 deletions(-) create mode 100644 web/app/components/base/chat/chat/chat-input-area/operation.tsx create mode 100644 web/app/components/base/file-uploader/file-list-flex/file-list-flex-operation.tsx create mode 100644 web/app/components/base/file-uploader/file-list-flex/file-list-item.tsx delete mode 100644 web/app/components/base/file-uploader/file-list/file-list-flex/index.tsx delete mode 100644 web/app/components/base/file-uploader/file-list/file-list-full-width/index.tsx delete mode 100644 web/app/components/base/file-uploader/file-list/hooks.ts delete mode 100644 web/app/components/base/file-uploader/file-list/index.tsx diff --git a/web/app/components/base/chat/chat/chat-input-area/hooks.ts b/web/app/components/base/chat/chat/chat-input-area/hooks.ts index 3559cb8799..5f54012a09 100644 --- a/web/app/components/base/chat/chat/chat-input-area/hooks.ts +++ b/web/app/components/base/chat/chat/chat-input-area/hooks.ts @@ -1,36 +1,47 @@ import { useCallback, - useEffect, - useMemo, useRef, useState, } from 'react' import type { TextAreaRef } from 'rc-textarea' export const useTextAreaHeight = () => { + const wrapperRef = useRef(null) const textareaRef = useRef(null) - const [height, setHeight] = useState(0) + const textValueRef = useRef(null) + const holdSpaceRef = useRef(null) + const [isMultipleLine, setIsMultipleLine] = useState(false) - const handleComputeHeight = () => { + const handleComputeHeight = useCallback(() => { const textareaElement = textareaRef.current?.resizableTextArea.textArea - if (textareaElement) { - const { height } = textareaElement.getBoundingClientRect() + if (wrapperRef.current && textareaElement && textValueRef.current && holdSpaceRef.current) { + const { width: wrapperWidth } = wrapperRef.current.getBoundingClientRect() + const { height: textareaHeight } = textareaElement.getBoundingClientRect() + const { width: textValueWidth } = textValueRef.current.getBoundingClientRect() + const { width: holdSpaceWidth } = holdSpaceRef.current.getBoundingClientRect() - setHeight(height) + if (textareaHeight > 32) { + setIsMultipleLine(true) + } + else { + if (textValueWidth + holdSpaceWidth >= wrapperWidth) + setIsMultipleLine(true) + else + setIsMultipleLine(false) + } } - } - - useEffect(() => { - handleComputeHeight() }, []) const handleTextareaResize = useCallback(() => { handleComputeHeight() - }, []) + }, [handleComputeHeight]) return { + wrapperRef, textareaRef, + textValueRef, + holdSpaceRef, handleTextareaResize, - isMultipleLine: useMemo(() => height > 32, [height]), + isMultipleLine, } } diff --git a/web/app/components/base/chat/chat/chat-input-area/index.tsx b/web/app/components/base/chat/chat/chat-input-area/index.tsx index be49248cb6..c79df7d7bb 100644 --- a/web/app/components/base/chat/chat/chat-input-area/index.tsx +++ b/web/app/components/base/chat/chat/chat-input-area/index.tsx @@ -1,49 +1,66 @@ import { memo, + useState, } from 'react' import Textarea from 'rc-textarea' -import { RiSendPlane2Fill } from '@remixicon/react' import { useTextAreaHeight } from './hooks' -import Button from '@/app/components/base/button' -import { FileUploaderInChatInput } from '@/app/components/base/file-uploader' +import Operation from './operation' import cn from '@/utils/classnames' +import { FileListFlexOperation } from '@/app/components/base/file-uploader' const ChatInputArea = () => { const { + wrapperRef, textareaRef, + textValueRef, + holdSpaceRef, handleTextareaResize, isMultipleLine, } = useTextAreaHeight() + const [value, setValue] = useState('') + + const operation = return (
-