feat: Implement input dialog for secret code submission and result display

This commit is contained in:
암냥 2025-12-24 13:30:13 +09:00
commit 481158dd85
No known key found for this signature in database

View file

@ -1,5 +1,16 @@
import Image from "next/image"; import Image from "next/image";
import { useState } from "react";
import { useIsMobile } from "@/hooks/use-mobile"; import { useIsMobile } from "@/hooks/use-mobile";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
interface TXTProps { interface TXTProps {
onHover?: (position: { x: number; y: number } | null) => void; onHover?: (position: { x: number; y: number } | null) => void;
@ -7,21 +18,79 @@ interface TXTProps {
export default function TXT({ onHover }: TXTProps) { export default function TXT({ onHover }: TXTProps) {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const [openInput, setOpenInput] = useState(false);
const [openResult, setOpenResult] = useState(false);
const [key, setKey] = useState("");
const [error, setError] = useState("");
const [content, setContent] = useState("");
const handleSubmit = async () => {
setError("");
setContent("");
try {
const response = await fetch(`https://api.imnya.ng/secret?key=${encodeURIComponent(key)}`);
const data = await response.text();
if (data === "false") {
setError("아니요?");
} else {
setOpenInput(false);
setOpenResult(true);
setContent(data);
}
} catch (_err) {
console.error(_err);
setError("오류가 발생했습니다");
}
};
if (isMobile) return null; if (isMobile) return null;
return ( return (
<div <>
className="flex flex-col items-center justify-center gap-4 absolute top-4 left-4 p-2 cursor-pointer font-galmuri drag-none select-none" <button
onMouseEnter={() => onHover?.({ x: 16, y: 16 })} type="button"
onMouseLeave={() => onHover?.(null)} className="flex flex-col items-center justify-center gap-4 absolute top-4 left-4 p-2 cursor-pointer font-galmuri drag-none select-none bg-transparent border-none"
onClick={() => { onMouseEnter={() => onHover?.({ x: 16, y: 16 })}
alert("왜 편법을 쓰지?"); onMouseLeave={() => onHover?.(null)}
window.location.reload(); onClick={() => setOpenInput(true)}
}} >
> <Image src="/txt.webp" alt="txt" width={24} height={24} />
<Image src="/txt.webp" alt="txt" width={24} height={24} /> <span className="text-sm font-medium text-foreground/80 font-galmuri">.txt</span>
<span className="text-sm font-medium text-foreground/80 font-galmuri">.txt</span> </button>
</div> <Dialog open={openInput} onOpenChange={setOpenInput}>
<DialogContent>
<DialogHeader>
<DialogTitle> </DialogTitle>
<DialogDescription>
.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<Input
placeholder="비밀 코드"
value={key}
onChange={(e) => setKey(e.target.value)}
/>
{error && <p className="text-red-500">{error}</p>}
</div>
<DialogFooter>
<Button onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
<Dialog open={openResult} onOpenChange={setOpenResult}>
<DialogContent>
<DialogHeader>
<DialogTitle>.txt</DialogTitle>
<DialogDescription>
{content}
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button onClick={() => setOpenResult(false)}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
); );
} }