diff --git a/src/app/(game)/scanner/page.tsx b/src/app/(game)/scanner/page.tsx index 1d5e4fc..143d486 100644 --- a/src/app/(game)/scanner/page.tsx +++ b/src/app/(game)/scanner/page.tsx @@ -7,12 +7,36 @@ import { getBoothToken } from "@/lib/getBoothToken"; import { sendPuzzle2Player } from "@/lib/sendPuzzle2Player"; import { useReadLocalStorage } from "usehooks-ts"; import { invalidToken, puzzleSuccess, puzzleTaken } from "@/lib/const"; +import { getPlayerPuzzle } from "@/lib/getPlayerPuzzle"; export default function Page() { + const playerToken: string | null = useReadLocalStorage("token"); + const [taken, setTaken] = useState(false); + + useEffect(() => { + if (!playerToken) return; + getPlayerPuzzle(playerToken) + .then((player) => { + if (typeof player.coupon === "number") setTaken(true); + }) + .catch(console.error); + }, [playerToken]); + + if (taken) { + return ( +
+
你已經領取過拼圖了
+
+ ); + } else { + return ; + } +} + +function Scan({ playerToken }: { playerToken: string | null }) { const [result, setResult] = useState(null); const [info, setInfo] = useState({ title: "", msg: "" }); const [showInfo, setShowInfo] = useState(false); - const playerToken: string | null = useReadLocalStorage("token"); useEffect(() => { async function handleResult() { if (showInfo) return;