|
| 1 | +/** |
| 2 | + * This code was generated by v0 by Vercel. |
| 3 | + * @see https://v0.dev/t/Vz30LKzXEsL |
| 4 | + */ |
| 5 | +import { Textarea } from "@/components/ui/textarea"; |
| 6 | +import { Button } from "@/components/ui/button"; |
| 7 | +import { OrginalGuess } from "@/app/page"; |
| 8 | +import { useState } from "react"; |
| 9 | +import { ReloadIcon } from "@radix-ui/react-icons"; |
| 10 | + |
| 11 | +type Props = { |
| 12 | + onSubmit: (text: string) => void; |
| 13 | + originalGuess?: OrginalGuess; |
| 14 | +}; |
| 15 | + |
| 16 | +export function EnterGuess({ onSubmit, originalGuess }: Props) { |
| 17 | + const [inputValue, setInputValue] = useState(""); |
| 18 | + |
| 19 | + const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { |
| 20 | + setInputValue(event.target.value); |
| 21 | + }; |
| 22 | + |
| 23 | + const handleSubmit = () => { |
| 24 | + onSubmit(inputValue); |
| 25 | + }; |
| 26 | + return ( |
| 27 | + <div className="flex h-screen w-full items-center justify-center bg-white p-8"> |
| 28 | + <div className="flex max-w-4xl flex-wrap items-center justify-center gap-8"> |
| 29 | + <div className="flex w-full justify-center"> |
| 30 | + <h1 className="text-3xl font-bold">Guess the prompt</h1> |
| 31 | + </div> |
| 32 | + <div className="grid grid-cols-2 gap-8 w-full"> |
| 33 | + <div className="relative"> |
| 34 | + {!originalGuess?.imageUrl && ( |
| 35 | + <ReloadIcon |
| 36 | + className="absolute z-10 h-8 w-8 animate-spin text-slate-800" |
| 37 | + style={{ |
| 38 | + top: "50%", |
| 39 | + left: "50%", |
| 40 | + }} |
| 41 | + /> |
| 42 | + )} |
| 43 | + <img |
| 44 | + className="h-[400px] w-[600px] object-cover" |
| 45 | + height="400" |
| 46 | + src={originalGuess?.imageUrl || "/placeholder.svg"} |
| 47 | + style={{ |
| 48 | + aspectRatio: "600/400", |
| 49 | + objectFit: "cover", |
| 50 | + }} |
| 51 | + width="600" |
| 52 | + /> |
| 53 | + </div> |
| 54 | + <div className="flex flex-col items-start space-y-4"> |
| 55 | + <p className="text-sm"> |
| 56 | + Can you guess the prompt used to generate this image? |
| 57 | + </p> |
| 58 | + <Textarea |
| 59 | + className="h-24 w-full resize-none rounded-md border p-2" |
| 60 | + placeholder="Guess the prompt used to generate the image" |
| 61 | + value={inputValue} |
| 62 | + onChange={handleInputChange} |
| 63 | + /> |
| 64 | + {originalGuess?.hints && ( |
| 65 | + <p className="text-sm">Hints: {originalGuess?.hints.join()}</p> |
| 66 | + )} |
| 67 | + <Button |
| 68 | + className="mt-2 w-full" |
| 69 | + onClick={handleSubmit} |
| 70 | + disabled={!originalGuess} |
| 71 | + > |
| 72 | + Submit |
| 73 | + </Button> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
0 commit comments