Skip to content

Commit

Permalink
lock scanner after took coupon
Browse files Browse the repository at this point in the history
  • Loading branch information
simbafs committed Mar 3, 2024
1 parent 3fc75f6 commit 4efed79
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/app/(game)/scanner/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex h-full items-center justify-center">
<div className="text-3xl">你已經領取過拼圖了</div>
</div>
);
} else {
return <Scan playerToken={playerToken} />;
}
}

function Scan({ playerToken }: { playerToken: string | null }) {
const [result, setResult] = useState<string | null>(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;
Expand Down

0 comments on commit 4efed79

Please sign in to comment.