Spaces:
Runtime error
Runtime error
wait 10ms on key down enter, to avoid any error with prompt state
Browse files- app/api/route.ts +0 -1
- components/button/index.tsx +4 -0
- components/input-generation.tsx +5 -1
- components/main/index.tsx +2 -1
app/api/route.ts
CHANGED
@@ -49,7 +49,6 @@ export async function POST(
|
|
49 |
}
|
50 |
|
51 |
const isNSFW: any = await checkIfIsNSFW(blob)
|
52 |
-
|
53 |
if (isNSFW?.error) return Response.json({ status: 500, ok: false, message: isNSFW?.error });
|
54 |
|
55 |
if (isNSFW?.length) {
|
|
|
49 |
}
|
50 |
|
51 |
const isNSFW: any = await checkIfIsNSFW(blob)
|
|
|
52 |
if (isNSFW?.error) return Response.json({ status: 500, ok: false, message: isNSFW?.error });
|
53 |
|
54 |
if (isNSFW?.length) {
|
components/button/index.tsx
CHANGED
@@ -2,11 +2,13 @@ import classNames from "classnames";
|
|
2 |
|
3 |
interface Props {
|
4 |
children: React.ReactNode;
|
|
|
5 |
theme?: "primary" | "secondary" | "white";
|
6 |
onClick?: () => void;
|
7 |
}
|
8 |
export const Button: React.FC<Props> = ({
|
9 |
children,
|
|
|
10 |
theme = "primary",
|
11 |
...props
|
12 |
}) => {
|
@@ -17,6 +19,8 @@ export const Button: React.FC<Props> = ({
|
|
17 |
{
|
18 |
"bg-primary text-white border-primary": theme === "primary",
|
19 |
"bg-white text-gray-900 border-white": theme === "white",
|
|
|
|
|
20 |
}
|
21 |
)}
|
22 |
{...props}
|
|
|
2 |
|
3 |
interface Props {
|
4 |
children: React.ReactNode;
|
5 |
+
disabled?: boolean;
|
6 |
theme?: "primary" | "secondary" | "white";
|
7 |
onClick?: () => void;
|
8 |
}
|
9 |
export const Button: React.FC<Props> = ({
|
10 |
children,
|
11 |
+
disabled,
|
12 |
theme = "primary",
|
13 |
...props
|
14 |
}) => {
|
|
|
19 |
{
|
20 |
"bg-primary text-white border-primary": theme === "primary",
|
21 |
"bg-white text-gray-900 border-white": theme === "white",
|
22 |
+
"!bg-gray-400 !text-gray-600 !cursor-not-allowed !border-gray-400":
|
23 |
+
disabled,
|
24 |
}
|
25 |
)}
|
26 |
{...props}
|
components/input-generation.tsx
CHANGED
@@ -3,6 +3,7 @@ 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 |
|
7 |
export const InputGeneration: React.FC = () => {
|
8 |
const { prompt, setPrompt, submit, loading } = useInputGeneration();
|
@@ -28,7 +29,10 @@ export const InputGeneration: React.FC = () => {
|
|
28 |
onBlur={() => setPrompt(value)}
|
29 |
onKeyDown={(e) => {
|
30 |
if (e.key === "Enter" && (value || prompt) && !loading) {
|
31 |
-
|
|
|
|
|
|
|
32 |
}
|
33 |
}}
|
34 |
/>
|
|
|
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();
|
|
|
29 |
onBlur={() => setPrompt(value)}
|
30 |
onKeyDown={(e) => {
|
31 |
if (e.key === "Enter" && (value || prompt) && !loading) {
|
32 |
+
setPrompt(value);
|
33 |
+
setTimeout(() => {
|
34 |
+
submit();
|
35 |
+
}, 10);
|
36 |
}
|
37 |
}}
|
38 |
/>
|
components/main/index.tsx
CHANGED
@@ -24,7 +24,7 @@ const categories = [
|
|
24 |
];
|
25 |
|
26 |
export const Main = () => {
|
27 |
-
const { list_styles, style, setStyle } = useInputGeneration();
|
28 |
const [category, setCategory] = useState<string>("community");
|
29 |
const [advancedSettings, setAdvancedSettings] = useState<boolean>(false);
|
30 |
|
@@ -37,6 +37,7 @@ export const Main = () => {
|
|
37 |
{categories.map(({ key, label, icon }) => (
|
38 |
<Button
|
39 |
key={key}
|
|
|
40 |
theme={key !== category ? "white" : "primary"}
|
41 |
onClick={() => setCategory(key)}
|
42 |
>
|
|
|
24 |
];
|
25 |
|
26 |
export const Main = () => {
|
27 |
+
const { list_styles, style, setStyle, loading } = useInputGeneration();
|
28 |
const [category, setCategory] = useState<string>("community");
|
29 |
const [advancedSettings, setAdvancedSettings] = useState<boolean>(false);
|
30 |
|
|
|
37 |
{categories.map(({ key, label, icon }) => (
|
38 |
<Button
|
39 |
key={key}
|
40 |
+
disabled={loading}
|
41 |
theme={key !== category ? "white" : "primary"}
|
42 |
onClick={() => setCategory(key)}
|
43 |
>
|