diff --git a/src/components/upload-audio/index.tsx b/src/components/upload-audio/index.tsx index 0b6e7c76..1a8e03d4 100644 --- a/src/components/upload-audio/index.tsx +++ b/src/components/upload-audio/index.tsx @@ -87,4 +87,4 @@ const UploadAudio: React.FC = (props) => { ); }; -export default React.memo(UploadAudio); +export default UploadAudio; diff --git a/src/pages/playground/components/ground-stt.tsx b/src/pages/playground/components/ground-stt.tsx index 6a5026cf..7967d54f 100644 --- a/src/pages/playground/components/ground-stt.tsx +++ b/src/pages/playground/components/ground-stt.tsx @@ -201,9 +201,11 @@ const GroundSTT: React.FC = forwardRef((props, ref) => { const handleUploadChange = useCallback( async (data: { file: any; fileList: any }) => { - const res = await readAudioFile(data.file); - setAudioData(res); - setTokenResult(null); + try { + const res = await readAudioFile(data.file); + setAudioData(res); + setTokenResult(null); + } catch (error) {} }, [] ); diff --git a/src/pages/playground/components/message-input.tsx b/src/pages/playground/components/message-input.tsx index 9aa1ba8d..d4e52e5c 100644 --- a/src/pages/playground/components/message-input.tsx +++ b/src/pages/playground/components/message-input.tsx @@ -1,5 +1,4 @@ import SimpleAudio from '@/components/audio-player/simple-audio'; -import DropDownActions from '@/components/drop-down-actions'; import IconFont from '@/components/icon-font'; import UploadAudio from '@/components/upload-audio'; import HotKeys, { KeyMap } from '@/config/hotkeys'; @@ -11,11 +10,8 @@ import { import { ClearOutlined, CustomerServiceOutlined, - LinkOutlined, - PictureOutlined, SendOutlined, - SwapOutlined, - UploadOutlined + SwapOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Checkbox, Divider, Input, Tooltip } from 'antd'; @@ -32,9 +28,9 @@ import { useHotkeys } from 'react-hotkeys-hook'; import styled from 'styled-components'; import { Roles } from '../config'; import { AudioFormat, MessageItem } from '../config/types'; +import useAddImage from '../hooks/use-add-image'; import '../style/message-input.less'; import ThumbImg from './thumb-img'; -import UploadImg from './upload-img'; const AudioWrapper = styled.div` padding-block: 10px; @@ -300,39 +296,6 @@ const MessageInput: React.FC = forwardRef( }); }; - const handleInputImageUrl = (e: any) => { - const url = e.target.value; - // ends with .png, .jpg, .jpeg - const regex = /(https?:\/\/\S+\.(png|jpg|jpeg))/gi; - const isValid = regex.test(url); - setOpenImgTips(!isValid); - if (!isValid) { - return; - } - handleUpdateImgList([ - { - uid: updateUidCount(), - dataUrl: e.target.value - } - ]); - setIsFromUrl(false); - setOpenImgTips(false); - }; - - const handleOnEscape = (e: any) => { - if (e.key === 'Escape') { - setIsFromUrl(false); - setOpenImgTips(false); - } - }; - - const handleAddImgFromUrl = () => { - setIsFromUrl(true); - setTimeout(() => { - inputImgRef.current?.focus?.(); - }, 100); - }; - const handleUploadAudioChange = async (data: { file: any; fileList: any[]; @@ -398,6 +361,11 @@ const MessageInput: React.FC = forwardRef( } }; + const { ImageURLInput, UploadImageButton } = useAddImage({ + handleUpdateImgList: handleUpdateImgList, + updateUidCount: updateUidCount + }); + useImperativeHandle(ref, () => ({ handleInputChange: handleInputChange })); @@ -451,41 +419,9 @@ const MessageInput: React.FC = forwardRef( {checkLabel} )} - {actions.includes('upload') && message.role === Roles.User && ( - - {intl.formatMessage({ id: 'playground.img.upload' })} - - ), - key: 'upload_image', - icon: - }, - { - label: intl.formatMessage({ - id: 'playground.uploadImage.url.button' - }), - key: 'add_image_url', - icon: , - onClick: handleAddImgFromUrl - } - ] - }} - > - - - )} + {actions.includes('upload') && + message.role === Roles.User && + UploadImageButton} {actions.includes('upload') && message.role === Roles.User && ( = forwardRef( ))} )} + {ImageURLInput}
{actions.includes('add') && ( @@ -603,26 +540,7 @@ const MessageInput: React.FC = forwardRef( )} - {isFromUrl && ( - - - - )} +
{actions.includes('paste') ? (