Spaces:
Runtime error
Runtime error
if empty string return
Browse files
components/input-generation.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import { useRef, useState } from "react";
|
|
| 3 |
import { HiLightBulb, HiSearch } from "react-icons/hi";
|
| 4 |
import { useUpdateEffect } from "react-use";
|
| 5 |
import { useInputGeneration } from "./main/hooks/useInputGeneration";
|
| 6 |
-
import { set } from "lodash";
|
| 7 |
|
| 8 |
export const InputGeneration: React.FC = () => {
|
| 9 |
const { prompt, setPrompt, submit, loading } = useInputGeneration();
|
|
@@ -28,12 +27,7 @@ export const InputGeneration: React.FC = () => {
|
|
| 28 |
onChange={(e) => setValue(e.target.value)}
|
| 29 |
onBlur={() => setPrompt(value)}
|
| 30 |
onKeyDown={(e) => {
|
| 31 |
-
if (
|
| 32 |
-
e.key === "Enter" &&
|
| 33 |
-
(value || prompt) &&
|
| 34 |
-
!loading &&
|
| 35 |
-
(value !== "" || prompt !== "")
|
| 36 |
-
) {
|
| 37 |
setPrompt(value);
|
| 38 |
setTimeout(() => {
|
| 39 |
submit();
|
|
@@ -51,8 +45,7 @@ export const InputGeneration: React.FC = () => {
|
|
| 51 |
}
|
| 52 |
)}
|
| 53 |
onClick={() => {
|
| 54 |
-
if ((!value && !prompt) || loading
|
| 55 |
-
return;
|
| 56 |
submit();
|
| 57 |
}}
|
| 58 |
>
|
|
|
|
| 3 |
import { HiLightBulb, HiSearch } from "react-icons/hi";
|
| 4 |
import { useUpdateEffect } from "react-use";
|
| 5 |
import { useInputGeneration } from "./main/hooks/useInputGeneration";
|
|
|
|
| 6 |
|
| 7 |
export const InputGeneration: React.FC = () => {
|
| 8 |
const { prompt, setPrompt, submit, loading } = useInputGeneration();
|
|
|
|
| 27 |
onChange={(e) => setValue(e.target.value)}
|
| 28 |
onBlur={() => setPrompt(value)}
|
| 29 |
onKeyDown={(e) => {
|
| 30 |
+
if (e.key === "Enter" && (value || prompt) && !loading) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
setPrompt(value);
|
| 32 |
setTimeout(() => {
|
| 33 |
submit();
|
|
|
|
| 45 |
}
|
| 46 |
)}
|
| 47 |
onClick={() => {
|
| 48 |
+
if ((!value && !prompt) || loading) return;
|
|
|
|
| 49 |
submit();
|
| 50 |
}}
|
| 51 |
>
|
components/main/hooks/useInputGeneration.ts
CHANGED
|
@@ -36,7 +36,9 @@ export const useInputGeneration = () => {
|
|
| 36 |
const { mutate: submit, isLoading: loading } = useMutation(
|
| 37 |
["generation"],
|
| 38 |
async () => {
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
const id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
|
| 41 |
if (!hasMadeFirstGeneration) setFirstGenerationDone()
|
| 42 |
client.setQueryData(["collections"], (old: any) => {
|
|
|
|
| 36 |
const { mutate: submit, isLoading: loading } = useMutation(
|
| 37 |
["generation"],
|
| 38 |
async () => {
|
| 39 |
+
const removeAllEmptySpace = prompt?.replace(/\s/g, '')
|
| 40 |
+
if (removeAllEmptySpace === '') return null
|
| 41 |
+
|
| 42 |
const id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
|
| 43 |
if (!hasMadeFirstGeneration) setFirstGenerationDone()
|
| 44 |
client.setQueryData(["collections"], (old: any) => {
|