Skip to content
Snippets Groups Projects
Unverified Commit 3390ccf4 authored by Sean Hatfield's avatar Sean Hatfield Committed by GitHub
Browse files

Improve PromptInput component (#3266)

* allow typing while streaming + refactor props

* remove duplicate function
parent eeaa6b01
No related branches found
No related tags found
No related merge requests found
...@@ -24,8 +24,7 @@ const MAX_EDIT_STACK_SIZE = 100; ...@@ -24,8 +24,7 @@ const MAX_EDIT_STACK_SIZE = 100;
export default function PromptInput({ export default function PromptInput({
submit, submit,
onChange, onChange,
inputDisabled, isStreaming,
buttonDisabled,
sendCommand, sendCommand,
attachments = [], attachments = [],
}) { }) {
...@@ -49,11 +48,6 @@ export default function PromptInput({ ...@@ -49,11 +48,6 @@ export default function PromptInput({
setPromptInput(e?.detail ?? ""); setPromptInput(e?.detail ?? "");
} }
function resetTextAreaHeight() {
if (!textareaRef.current) return;
textareaRef.current.style.height = "auto";
}
useEffect(() => { useEffect(() => {
if (!!window) if (!!window)
window.addEventListener(PROMPT_INPUT_EVENT, handlePromptUpdate); window.addEventListener(PROMPT_INPUT_EVENT, handlePromptUpdate);
...@@ -62,9 +56,9 @@ export default function PromptInput({ ...@@ -62,9 +56,9 @@ export default function PromptInput({
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!inputDisabled && textareaRef.current) textareaRef.current.focus(); if (!isStreaming && textareaRef.current) textareaRef.current.focus();
resetTextAreaHeight(); resetTextAreaHeight();
}, [inputDisabled]); }, [isStreaming]);
/** /**
* Save the current state before changes * Save the current state before changes
...@@ -115,6 +109,7 @@ export default function PromptInput({ ...@@ -115,6 +109,7 @@ export default function PromptInput({
// Is simple enter key press w/o shift key // Is simple enter key press w/o shift key
if (event.keyCode === 13 && !event.shiftKey) { if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault(); event.preventDefault();
if (isStreaming) return;
return submit(event); return submit(event);
} }
...@@ -264,7 +259,6 @@ export default function PromptInput({ ...@@ -264,7 +259,6 @@ export default function PromptInput({
handlePasteEvent(e); handlePasteEvent(e);
}} }}
required={true} required={true}
disabled={inputDisabled}
onFocus={() => setFocused(true)} onFocus={() => setFocused(true)}
onBlur={(e) => { onBlur={(e) => {
setFocused(false); setFocused(false);
...@@ -274,7 +268,7 @@ export default function PromptInput({ ...@@ -274,7 +268,7 @@ export default function PromptInput({
className={`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow ${textSizeClass}`} className={`border-none cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow ${textSizeClass}`}
placeholder={"Send a message"} placeholder={"Send a message"}
/> />
{buttonDisabled ? ( {isStreaming ? (
<StopGenerationButton /> <StopGenerationButton />
) : ( ) : (
<> <>
......
...@@ -282,8 +282,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) { ...@@ -282,8 +282,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
<PromptInput <PromptInput
submit={handleSubmit} submit={handleSubmit}
onChange={handleMessageChange} onChange={handleMessageChange}
inputDisabled={loadingResponse} isStreaming={loadingResponse}
buttonDisabled={loadingResponse}
sendCommand={sendCommand} sendCommand={sendCommand}
attachments={files} attachments={files}
/> />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment