Skip to content

Commit

Permalink
prevent new message hwhen loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcccsliu committed Mar 31, 2024
1 parent 7e307ca commit 6d75e5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/components/AutoResizeTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Textarea, TextareaProps } from "@chakra-ui/react";
interface AutoResizeTextareaProps extends TextareaProps {
maxHeight?: string;
onSendMessage?: () => void;
isLoading: boolean;
}

const AutoResizeTextarea: React.FC<AutoResizeTextareaProps> = ({
Expand All @@ -13,12 +14,13 @@ const AutoResizeTextarea: React.FC<AutoResizeTextareaProps> = ({
placeholder,
maxHeight = "200px",
onSendMessage,
isLoading,
...rest
}) => {
const textareaRef = useRef<HTMLTextAreaElement>(null);

const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
if ((event.metaKey || event.ctrlKey) && event.key === "Enter" && !isLoading) {
event.preventDefault();
if (onSendMessage) {
onSendMessage();
Expand Down
1 change: 1 addition & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export default function Home() {
borderRadius="none"
borderColor="black"
minHeight="40px"
isLoading={loading}
onSendMessage={() =>
handleSendMessage(
textValue,
Expand Down

0 comments on commit 6d75e5c

Please sign in to comment.