From 0a3c25aa3574e71b10bcb9f699f23888acfabc24 Mon Sep 17 00:00:00 2001 From: Alexander Grattan Date: Fri, 26 Jul 2024 12:09:31 -0400 Subject: [PATCH] revert: undo changes to prompt component --- apps/client/src/components/game/prompt.tsx | 110 +++++++++------------ 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/apps/client/src/components/game/prompt.tsx b/apps/client/src/components/game/prompt.tsx index 27b88e0..994fa4d 100644 --- a/apps/client/src/components/game/prompt.tsx +++ b/apps/client/src/components/game/prompt.tsx @@ -14,7 +14,6 @@ import toast from "react-hot-toast"; import { FiHelpCircle, FiX } from "react-icons/fi"; import useSound from "use-sound"; import type { Session } from "next-auth"; -import { captureException } from "@sentry/nextjs"; import Button, { SecondaryButton } from "@ai/components/button"; import Ellipsis from "@ai/components/ellipsis"; @@ -110,54 +109,45 @@ const Prompt = ({ const outOfRegenerations = remainingImageGenerations === 0; const onPromptSubmit = async (e: FormEvent) => { - try { - e.preventDefault(); - setLoading(true); + e.preventDefault(); + setLoading(true); - const formPrompt = e.currentTarget.elements.prompt.value; - setImagePrompt(formPrompt); + const formPrompt = e.currentTarget.elements.prompt.value; + setImagePrompt(formPrompt); - console.time("Execution Time"); + console.time("Execution Time"); - const images = await generateSDXLImages(formPrompt); + const images = await generateSDXLImages(formPrompt); - console.timeEnd("Execution Time"); + console.timeEnd("Execution Time"); - if (!images || !Array.isArray(images) || images.length !== 2) { - throw new Error( - "Images wasn't defined or the incorrect amount of images were returned", - ); - } - - if (!userId) { - throw new Error("User id not defined when creating generations"); - } - - const generations = await createGenerations({ - userId, - gameId, - questionId: currQuestion.id, - images: images?.map((image) => { - return { - text: formPrompt, - imageUrl: image, - }; - }), - }); + if (images && Array.isArray(images) && images.length === 2) { + if (userId) { + const generations = await createGenerations({ + userId, + gameId, + questionId: currQuestion.id, + images: images?.map((image) => { + return { + text: formPrompt, + imageUrl: image, + }; + }), + }); - setImageOption1(generations[0]); - setImageOption2(generations[1]); + setImageOption1(generations[0]); + setImageOption2(generations[1]); - setCurrQuestionNumGenerations( - currQuestionNumGenerations + generations.length, - ); - } catch (error) { + setCurrQuestionNumGenerations( + currQuestionNumGenerations + generations.length, + ); + } + } else { console.error("Images were unable to be generated"); toast.error("I'm afraid I don't know how to process such a request."); - captureException(error); - } finally { - setLoading(false); } + + setLoading(false); }; const resetImage = () => { @@ -171,38 +161,34 @@ const Prompt = ({ }; const onImageSubmit = async () => { - try { - setLoading(true); - - if (!session || !imageOption1 || !imageOption2) { - throw new Error( - "User was not defined when trying to submit a generation", - ); - } + setLoading(true); + if (session && imageOption1 && imageOption2) { socket.emit("generationSubmitted", { generationId: selectedImage === 1 ? imageOption1?.id : imageOption2?.id, gameId: gameId, round: currRound, }); - - if (stage === "FIRST") { - setCurrQuestionNumGenerations(0); - setStage("SECOND"); - setImagePrompt(""); - resetImage(); - } else { - if (soundEnabled) { - play(); - } - send({ type: "SUBMIT" }); - } - } catch (error) { + } else { + console.error("User was not defined when trying to submit a generation"); toast.error("Oops, we can't submit your generation."); - captureException(error); - } finally { setLoading(false); + return; } + + if (stage === "FIRST") { + setCurrQuestionNumGenerations(0); + setStage("SECOND"); + setImagePrompt(""); + resetImage(); + } else { + if (soundEnabled) { + play(); + } + send({ type: "SUBMIT" }); + } + + setLoading(false); }; useEffect(() => {