diff --git a/web/src/components/Playing.tsx b/web/src/components/Playing.tsx index 7253fdf1..5574dbad 100644 --- a/web/src/components/Playing.tsx +++ b/web/src/components/Playing.tsx @@ -42,6 +42,7 @@ const Playing = () => { const [inviteFrom, setInviteFrom] = useState(""); const [inviteSession, setInviteSession] = useState(""); const [inviteCode, setInviteCode] = useState(""); + const [inviteRole, setInviteRole] = useState(""); const router = useRouter(); useEffect(() => { @@ -60,7 +61,12 @@ const Playing = () => { } else { setInviteCode(""); } - }, [router.query.invite_from, router.query.id, router.query.invite_code]); + if (router.query.role && typeof router.query.role === "string") { + setInviteRole(router.query.role); + } else { + setInviteRole(""); + } + }, [router.query.invite_from, router.query.id, router.query.invite_code, router.query.role]); const ownedTokens = useQuery( ["owned_tokens", user], @@ -232,6 +238,7 @@ const Playing = () => { )} {inviteFrom && inviteSession && ownedTokens.data && ownedTokens.data.length > 0 && ( !t.isStaked || t.tokenProgress === 6)} sessionID={Number(inviteSession)} inviteCode={inviteCode} diff --git a/web/src/components/atbat/InviteLinkView.tsx b/web/src/components/atbat/InviteLinkView.tsx index 355598c2..3ae5c9e8 100644 --- a/web/src/components/atbat/InviteLinkView.tsx +++ b/web/src/components/atbat/InviteLinkView.tsx @@ -14,13 +14,14 @@ const InviteLinkView = ({ atBat }: { atBat: AtBatStatus }) => { String(atBat.pitches[0].sessionID), ); const inviteCode = getLocalStorageItem(inviteCodeKey); + const inviteCodeParam = inviteCode ? `&invite_code=${inviteCode}` : ""; + const role = atBat.pitcher ? 1 : atBat.batter ? 0 : undefined; + const roleParam = role !== undefined ? `&role=${role}` : ""; const link = `${window.location.protocol}//${ window.location.host }/?invite_from=${encodeURIComponent( atBat.pitcher ? atBat.pitcher.name : atBat.batter ? atBat.batter.name : "", - )}&id=${atBat.pitches[0].sessionID}${inviteCode ? "&invite_code=" : ""}${ - inviteCode ? inviteCode : "" - }`; + )}&id=${atBat.pitches[0].sessionID}${roleParam}${inviteCodeParam}`; const { onCopy, hasCopied } = useClipboard(link); return ( diff --git a/web/src/components/tokens/ChooseToken.tsx b/web/src/components/tokens/ChooseToken.tsx index 2d49ab05..50d89c5b 100644 --- a/web/src/components/tokens/ChooseToken.tsx +++ b/web/src/components/tokens/ChooseToken.tsx @@ -33,12 +33,14 @@ const ChooseToken = ({ sessionID, inviteCode, inviteFrom, + inviteRole, }: { tokens: OwnedToken[]; onClose: () => void; sessionID: number; inviteCode: string; inviteFrom: string; + inviteRole: string; }) => { const { updateContext, selectedTokenIdx } = useGameContext(); @@ -200,7 +202,7 @@ const ChooseToken = ({ Cancel