Skip to content

Commit

Permalink
invite role
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Mushnin committed May 10, 2024
1 parent 9e8f96a commit adb39e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion web/src/components/Playing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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<OwnedToken[]>(
["owned_tokens", user],
Expand Down Expand Up @@ -232,6 +238,7 @@ const Playing = () => {
)}
{inviteFrom && inviteSession && ownedTokens.data && ownedTokens.data.length > 0 && (
<ChooseToken
inviteRole={inviteRole}
tokens={ownedTokens.data.filter((t) => !t.isStaked || t.tokenProgress === 6)}
sessionID={Number(inviteSession)}
inviteCode={inviteCode}
Expand Down
7 changes: 4 additions & 3 deletions web/src/components/atbat/InviteLinkView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/tokens/ChooseToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -200,7 +202,7 @@ const ChooseToken = ({
Cancel
</button>
<button type={"button"} className={parentStyles.button} onClick={handleClick}>
{joinSession.isLoading ? <Spinner /> : "Play"}
{joinSession.isLoading ? <Spinner /> : inviteRole === "0" ? "Pitch" : "Bat"}
</button>
</div>
</>
Expand Down

0 comments on commit adb39e9

Please sign in to comment.