From af22dfb6864907941052813944a36db52a85cde1 Mon Sep 17 00:00:00 2001 From: SuperTurk Date: Sat, 6 Jan 2024 11:12:25 +0100 Subject: [PATCH] feat: New way to stop the loading task (#631) --- .../organisms/chat/inputBox/SubmitButton.tsx | 49 +++++++++++++++++++ .../organisms/chat/inputBox/index.tsx | 2 - .../organisms/chat/inputBox/input.tsx | 16 +----- .../components/organisms/chat/stopButton.tsx | 31 ------------ 4 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 frontend/src/components/organisms/chat/inputBox/SubmitButton.tsx delete mode 100644 frontend/src/components/organisms/chat/stopButton.tsx diff --git a/frontend/src/components/organisms/chat/inputBox/SubmitButton.tsx b/frontend/src/components/organisms/chat/inputBox/SubmitButton.tsx new file mode 100644 index 0000000000..2d3f3b4e44 --- /dev/null +++ b/frontend/src/components/organisms/chat/inputBox/SubmitButton.tsx @@ -0,0 +1,49 @@ +import StopCircle from '@mui/icons-material/StopCircle'; +import Telegram from '@mui/icons-material/Telegram'; +import { Tooltip } from '@mui/material'; +import Box from '@mui/material/Box'; +import IconButton from '@mui/material/IconButton'; +import InputAdornment from '@mui/material/InputAdornment'; + +import { useChatData, useChatInteract } from '@chainlit/react-client'; + +interface SubmitButtonProps { + disabled?: boolean; + onSubmit: () => void; +} + +const SubmitButton = ({ disabled, onSubmit }: SubmitButtonProps) => { + const { loading } = useChatData(); + const { stopTask } = useChatInteract(); + + const handleClick = () => { + stopTask(); + }; + + return ( + + {!loading ? ( + + + + + + + + ) : ( + + + + + + )} + + ); +}; + +export { SubmitButton }; diff --git a/frontend/src/components/organisms/chat/inputBox/index.tsx b/frontend/src/components/organisms/chat/inputBox/index.tsx index 7d3239f723..0a55c11703 100644 --- a/frontend/src/components/organisms/chat/inputBox/index.tsx +++ b/frontend/src/components/organisms/chat/inputBox/index.tsx @@ -11,7 +11,6 @@ import { IAttachment } from 'state/chat'; import { IProjectSettings } from 'state/project'; import { inputHistoryState } from 'state/userInputHistory'; -import StopButton from '../stopButton'; import Input from './input'; import WaterMark from './waterMark'; @@ -106,7 +105,6 @@ const InputBox = memo( justifyContent: 'center' }} > - ); - const endAdornment = ( - submit()}> - - - ); return ( ), - endAdornment: ( - - {endAdornment} - - ) + endAdornment: }} /> diff --git a/frontend/src/components/organisms/chat/stopButton.tsx b/frontend/src/components/organisms/chat/stopButton.tsx deleted file mode 100644 index 7403009f7e..0000000000 --- a/frontend/src/components/organisms/chat/stopButton.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import CloseIcon from '@mui/icons-material/Close'; -import { Box } from '@mui/material'; - -import { useChatData, useChatInteract } from '@chainlit/react-client'; -import { GreyButton } from '@chainlit/react-components'; - -export default function StopButton() { - const { loading } = useChatData(); - const { stopTask } = useChatInteract(); - - if (!loading) { - return null; - } - - const handleClick = () => { - stopTask(); - }; - - return ( - - } - variant="contained" - onClick={handleClick} - > - Stop task - - - ); -}