Skip to content

Commit

Permalink
Fix url-based name entry not working
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerkrewson committed Jul 28, 2024
1 parent f844963 commit 1fad6a4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pages/[gameCode].js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ const Game = ({ loading }) => {
Swal.fire(lockedMessage(minutes)).then(() => router.push("/")),
);

const urlParams = new URLSearchParams(window.location.search);

const isRocketcrab = urlParams.get("rocketcrab") === "true";
const name = urlParams.get("name");

if (isRocketcrab && name) {
setIsRocketcrab(true);
onNameEntry(name);
}

return function cleanup() {
socket.close();
setGameState({ status: "loading" });
Expand All @@ -75,18 +85,6 @@ const Game = ({ loading }) => {
setCookie(null, "previousName", name);
};

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);

const isRocketcrab = urlParams.get("rocketcrab") === "true";
const name = urlParams.get("name");

if (isRocketcrab && name) {
setIsRocketcrab(true);
onNameEntry(name);
}
}, []);

const { status, me } = gameState;

const showLoading = status === "loading" || loading;
Expand Down

0 comments on commit 1fad6a4

Please sign in to comment.