From 93008c34d3f0f220f82dac7ff7794749354d42e3 Mon Sep 17 00:00:00 2001 From: Ishaan Dey Date: Tue, 14 May 2024 01:13:57 -0700 Subject: [PATCH] fully working ai limiting --- frontend/components/editor/editor.tsx | 8 ++++++++ frontend/components/editor/generate.tsx | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/components/editor/editor.tsx b/frontend/components/editor/editor.tsx index 816a114..f8fcda1 100644 --- a/frontend/components/editor/editor.tsx +++ b/frontend/components/editor/editor.tsx @@ -604,6 +604,14 @@ export default function CodeEditor({ const updatedFile = lines.join("\n"); editorRef?.setValue(updatedFile); }} + onClose={() => { + setGenerate((prev) => { + return { + ...prev, + show: !prev.show, + }; + }); + }} /> ) : null} diff --git a/frontend/components/editor/generate.tsx b/frontend/components/editor/generate.tsx index f9c16ca..794a502 100644 --- a/frontend/components/editor/generate.tsx +++ b/frontend/components/editor/generate.tsx @@ -18,6 +18,7 @@ export default function GenerateInput({ editor, onExpand, onAccept, + onClose, }: { user: User; socket: Socket; @@ -32,6 +33,7 @@ export default function GenerateInput({ }; onExpand: () => void; onAccept: (code: string) => void; + onClose: () => void; }) { const pathname = usePathname(); const router = useRouter(); @@ -61,6 +63,7 @@ export default function GenerateInput({ toast.error( "You reached the maximum # of generations. Contact @ishaandey_ on X/Twitter to reset :)" ); + return; } setLoading({ generate: !regenerate, regenerate }); @@ -72,10 +75,11 @@ export default function GenerateInput({ data.line, regenerate ? currentPrompt : input, (res: { response: string; success: boolean }) => { - if (!res.success) { - toast.error("Failed to generate code."); - return; - } + console.log("Generated code", res.response, res.success); + // if (!res.success) { + // toast.error("Failed to generate code."); + // return; + // } setCode(res.response); router.refresh(); @@ -122,6 +126,14 @@ export default function GenerateInput({ )} + {expanded ? ( <>