diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx index 4c148575c..bfc7b65c9 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx @@ -1,9 +1,17 @@ +import useFlowStore from "@/stores/flowStore"; import IconComponent from "../../../../../../../components/genericIconComponent"; import { Button } from "../../../../../../../components/ui/button"; import { Case } from "../../../../../../../shared/components/caseComponent"; import { FilePreviewType } from "../../../../../../../types/components"; import { classNames } from "../../../../../../../utils/utils"; +const BUTTON_STATES = { + NO_INPUT: "bg-high-indigo text-background", + HAS_CHAT_VALUE: "text-primary", + SHOW_STOP: "bg-error text-background cursor-pointer", + DEFAULT: "bg-chat-send text-background", +}; + type ButtonSendWrapperProps = { send: () => void; lockChat: boolean; @@ -19,29 +27,48 @@ const ButtonSendWrapper = ({ chatValue, files, }: ButtonSendWrapperProps) => { + const stopBuilding = useFlowStore((state) => state.stopBuilding); + + const isBuilding = useFlowStore((state) => state.isBuilding); + const showStopButton = lockChat || files.some((file) => file.loading); + const showPlayButton = !lockChat && noInput; + const showSendButton = + !(lockChat || files.some((file) => file.loading)) && !noInput; + + const getButtonState = () => { + if (showStopButton) return BUTTON_STATES.SHOW_STOP; + if (noInput) return BUTTON_STATES.NO_INPUT; + if (chatValue) return BUTTON_STATES.HAS_CHAT_VALUE; + + return BUTTON_STATES.DEFAULT; + }; + + const buttonClasses = classNames("form-modal-send-button", getButtonState()); + + const handleClick = () => { + if (showStopButton && isBuilding) { + stopBuilding(); + } else if (!showStopButton) { + send(); + } + }; + return (