Skip to content

Commit

Permalink
Disable send button when input is blank
Browse files Browse the repository at this point in the history
Updated Virtual Assistant to pull in onChange and used it to modify the send button state.
  • Loading branch information
rebeccaalpert committed Nov 7, 2024
1 parent a9610da commit b129f24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@patternfly/react-core": "^6.0.0",
"@patternfly/react-icons": "^6.0.0",
"@patternfly/react-styles": "^6.0.0",
"@patternfly/virtual-assistant": "^2.1.0-prerelease.8",
"@patternfly/virtual-assistant": "^2.1.0-prerelease.11",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sirv-cli": "^2.0.2"
Expand Down
10 changes: 10 additions & 0 deletions src/app/BaseChatbot/BaseChatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Source {

const BaseChatbot: React.FunctionComponent = () => {
const { chatbots } = useLoaderData() as { chatbots: CannedChatbot[] };
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(true);
const [messages, setMessages] = React.useState<MessageProps[]>([]);
const [currentMessage, setCurrentMessage] = React.useState<string[]>([]);
const [currentSources, setCurrentSources] = React.useState<Source[]>();
Expand Down Expand Up @@ -229,6 +230,14 @@ const BaseChatbot: React.FunctionComponent = () => {
setHasStopButton(false);
};

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {

Check failure on line 233 in src/app/BaseChatbot/BaseChatbot.tsx

View workflow job for this annotation

GitHub Actions / Lint

'handleChange' is assigned a value but never used
if (value !== '') {
setIsSendButtonDisabled(false);
return;
}
setIsSendButtonDisabled(true);
};

return (
<Chatbot displayMode={displayMode}>
<ChatbotHeader>
Expand Down Expand Up @@ -281,6 +290,7 @@ const BaseChatbot: React.FunctionComponent = () => {
hasStopButton={hasStopButton}
handleStopButton={handleStopButton}
alwayShowSendButton
isSendButtonDisabled={isSendButtonDisabled}
/>
<ChatbotFootnote label="Verify all information from this tool. LLMs make mistakes." />
</ChatbotFooter>
Expand Down
11 changes: 11 additions & 0 deletions src/app/Compare/CompareLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const CompareLayout: React.FunctionComponent = () => {
const { chatbots } = useLoaderData() as { chatbots: CannedChatbot[] };

// state
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(true);
const [input, setInput] = React.useState<string>();
const [hasNewInput, setHasNewInput] = React.useState(false);
const [firstController, setFirstController] = React.useState<AbortController>();
Expand Down Expand Up @@ -117,6 +118,14 @@ export const CompareLayout: React.FunctionComponent = () => {
setHasStopButton(false);
};

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
if (value !== '') {
setIsSendButtonDisabled(false);
return;
}
setIsSendButtonDisabled(true);
};

return (
firstChatbot &&
secondChatbot && (
Expand Down Expand Up @@ -175,6 +184,8 @@ export const CompareLayout: React.FunctionComponent = () => {
hasStopButton={hasStopButton}
handleStopButton={handleStopButton}
alwayShowSendButton
onChange={handleChange}
isSendButtonDisabled={isSendButtonDisabled}
/>
<ChatbotFootnote label="Verify all information from this tool. LLMs make mistakes." />
</ChatbotFooter>
Expand Down

0 comments on commit b129f24

Please sign in to comment.