Skip to content

Commit

Permalink
Add useRouter hook and refactor Scanner component
Browse files Browse the repository at this point in the history
  • Loading branch information
gnehs committed Mar 2, 2024
1 parent 1c8b699 commit f14c20c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
31 changes: 16 additions & 15 deletions src/app/(game)/scanner/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useEffect, useState } from "react";
import Scanner from "@/components/Scanner";

import { useRouter } from "next/router";
import { InfoWindow } from "@/components/InfoWindow";
import { getBoothToken } from "@/lib/getBoothToken";
import { sendPuzzle2Player } from "@/lib/sendPuzzle2Player";
Expand All @@ -14,7 +14,6 @@ export default function Page() {
const [info, setInfo] = useState({ title: "", msg: "" });
const [showInfo, setShowInfo] = useState(false);
const playerToken: string | null = useReadLocalStorage("token");

useEffect(() => {
async function handleResult() {
if (typeof result !== "string") return;
Expand Down Expand Up @@ -49,20 +48,22 @@ export default function Page() {

return (
<>
<Scanner
onResult={(result) => {
if (result.startsWith("http")) {
// get token from query string
const url = new URL(result);
const token = url.searchParams.get("token");
if (token) {
setResult(token);
{!showInfo && (
<Scanner
onResult={(result) => {
if (result.startsWith("http")) {
// get token from query string
const url = new URL(result);
const token = url.searchParams.get("token");
if (token) {
setResult(token);
}
} else {
setResult(result);
}
} else {
setResult(result);
}
}}
/>
}}
/>
)}
{showInfo && (
<InfoWindow
title={info.title}
Expand Down
8 changes: 3 additions & 5 deletions src/components/InfoWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ export function InfoWindow({ title, msg, onClose }: Props) {
<div
className="fixed left-0 top-0 h-full w-full bg-black bg-opacity-50"
onClick={onClose}
>
</div>
/>
<div className="z-50 rounded-lg bg-white p-6 shadow-md">
<div className="mb-4 flex items-center justify-between">
<h2 className="text-lg font-semibold text-gray-800">{title}</h2>
{/* <img src="" alt="" /> */}
<div className="mb-4 flex items-center justify-between text-lg font-semibold text-gray-800">
{title}
</div>
<p className="text-gray-700">{msg}</p>
</div>
Expand Down

0 comments on commit f14c20c

Please sign in to comment.