From 977723f71f7cf8ea005f2a777b582b5909fad6a3 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 9 Nov 2024 17:13:23 +0530 Subject: [PATCH] feat: Ability to send image without text --- src/components/Option/Playground/PlaygroundForm.tsx | 8 +++++--- src/components/Sidepanel/Chat/form.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index be312e2..4e0d637 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -159,7 +159,7 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { e.preventDefault() stopListening() form.onSubmit(async (value) => { - if (value.message.trim().length === 0) { + if (value.message.trim().length === 0 && value.image.length === 0) { return } if (!selectedModel || selectedModel.length === 0) { @@ -228,6 +228,9 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { return } } + if (value.message.trim().length === 0 && value.image.length === 0) { + return + } form.reset() textAreaFocus() await sendMessage({ @@ -261,7 +264,6 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { onKeyDown={(e) => handleKeyDown(e)} ref={textareaRef} className="px-2 py-2 w-full resize-none bg-transparent focus-within:outline-none focus:ring-0 focus-visible:ring-0 ring-0 dark:ring-0 border-0 dark:text-gray-100" - required onPaste={handlePaste} rows={1} style={{ minHeight: "40px" }} @@ -409,4 +411,4 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { ) -} +} \ No newline at end of file diff --git a/src/components/Sidepanel/Chat/form.tsx b/src/components/Sidepanel/Chat/form.tsx index e1cc3f0..618431d 100644 --- a/src/components/Sidepanel/Chat/form.tsx +++ b/src/components/Sidepanel/Chat/form.tsx @@ -75,10 +75,10 @@ export const SidepanelForm = ({ dropedFile }: Props) => { ) { e.preventDefault() form.onSubmit(async (value) => { - await stopListening() - if (value.message.trim().length === 0) { + if (value.message.trim().length === 0 && value.image.length === 0) { return } + await stopListening() if (!selectedModel || selectedModel.length === 0) { form.setFieldError("message", t("formError.noModel")) return @@ -237,6 +237,9 @@ export const SidepanelForm = ({ dropedFile }: Props) => { } } await stopListening() + if (value.message.trim().length === 0 && value.image.length === 0) { + return + } form.reset() textAreaFocus() await sendMessage({ @@ -260,7 +263,6 @@ export const SidepanelForm = ({ dropedFile }: Props) => { onKeyDown={(e) => handleKeyDown(e)} ref={textareaRef} className="px-2 py-2 w-full resize-none bg-transparent focus-within:outline-none focus:ring-0 focus-visible:ring-0 ring-0 dark:ring-0 border-0 dark:text-gray-100" - required onPaste={handlePaste} rows={1} style={{ minHeight: "60px" }}