Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invites #274

Merged
merged 25 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
81398ff
new icon
Anton-Mushnin May 6, 2024
9c1a1b3
hide scores and footer for progress === 2
Anton-Mushnin May 6, 2024
c288338
invite prompt
Anton-Mushnin May 6, 2024
eb97124
new icons
Anton-Mushnin May 6, 2024
720b577
link icon
Anton-Mushnin May 6, 2024
64a0698
tokens in invite view
Anton-Mushnin May 6, 2024
2d6a868
InviteLinkView
Anton-Mushnin May 6, 2024
0f19713
Choose Token View
Anton-Mushnin May 6, 2024
5ca6061
New character button update
Anton-Mushnin May 6, 2024
eb868e7
showing invite link in new atbat
Anton-Mushnin May 6, 2024
185dc0f
handling invites
Anton-Mushnin May 6, 2024
410b4ca
making PVPIcon respect fill prop
Anton-Mushnin May 7, 2024
bf9cf0f
invite to session instead of atbat
Anton-Mushnin May 7, 2024
57db991
opened invite layout
Anton-Mushnin May 7, 2024
427af6f
choosing token form update
Anton-Mushnin May 7, 2024
6e6a82a
cursor for clickable element
Anton-Mushnin May 7, 2024
5e77ff3
remove duplicate class
Anton-Mushnin May 8, 2024
4f5a36b
show invite info on login and signup
Anton-Mushnin May 8, 2024
ecca7a5
choosing token for invite if there is a token
Anton-Mushnin May 8, 2024
ac84f38
updating token after creation
Anton-Mushnin May 8, 2024
a03bec7
invite flow for not logged in user
Anton-Mushnin May 8, 2024
c49b958
updating ownedTokens after mint
Anton-Mushnin May 8, 2024
11c151f
checking if invite session is valid
Anton-Mushnin May 8, 2024
2eceedf
clear invite state after route change
Anton-Mushnin May 8, 2024
06014a2
Merge branch 'main' into invites
Anton-Mushnin May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions web/src/components/Playing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getMulticallResults } from "../utils/multicall";
import { AbiItem } from "web3-utils";
import FullcountABIImported from "../web3/abi/FullcountABI.json";
import { useSound } from "../hooks/useSound";
import { useRouter } from "next/router";
const FullcountABI = FullcountABIImported as unknown as AbiItem[];

const Playing = () => {
Expand All @@ -38,6 +39,28 @@ const Playing = () => {
} = useGameContext();
const { user } = useUser();
const playSound = useSound();
const [inviteFrom, setInviteFrom] = useState("");
const [inviteSession, setInviteSession] = useState("");
const [inviteCode, setInviteCode] = useState("");
const router = useRouter();

useEffect(() => {
if (router.query.invite_from && typeof router.query.invite_from === "string") {
setInviteFrom(router.query.invite_from);
} else {
setInviteFrom("");
}
if (router.query.id && typeof router.query.id === "string") {
setInviteSession(router.query.id);
} else {
setInviteSession("");
}
if (router.query.invite_code && typeof router.query.invite_code === "string") {
setInviteCode(router.query.invite_code);
} else {
setInviteCode("");
}
}, [router.query.invite_from, router.query.id, router.query.invite_code]);

const ownedTokens = useQuery<OwnedToken[]>(
["owned_tokens", user],
Expand All @@ -47,6 +70,15 @@ const Playing = () => {
if (ownedTokens.length > 0 && !selectedToken && ownedTokens[selectedTokenIdx]) {
updateContext({ selectedToken: { ...ownedTokens[selectedTokenIdx] } });
}
//first response from the FCPLayer API after token creation has empty name and p0 image
if (
selectedToken &&
!selectedToken.name &&
ownedTokens[selectedTokenIdx] &&
selectedToken.id === ownedTokens[selectedTokenIdx].id
) {
updateContext({ selectedToken: { ...ownedTokens[selectedTokenIdx] } });
}
return ownedTokens;
},
{
Expand Down Expand Up @@ -192,26 +224,26 @@ const Playing = () => {
ownedTokens.data &&
ownedTokens.data.length >= 1 &&
!invitedTo &&
!inviteFrom &&
!isCreateCharacter && (
<PlayingLayout>
<HomePage tokens={ownedTokens.data} atBats={atBats.data?.atBats} />
</PlayingLayout>
)}

{invitedTo && ownedTokens.data && !isCreateCharacter && (
{inviteFrom && inviteSession && ownedTokens.data && ownedTokens.data.length > 0 && (
<ChooseToken
tokens={ownedTokens.data}
onChoose={(token) => {
updateContext({ selectedToken: token, invitedTo: undefined });
tokens={ownedTokens.data.filter((t) => !t.isStaked)}
sessionID={Number(inviteSession)}
inviteCode={inviteCode}
inviteFrom={inviteFrom}
onClose={() => {
router.push("/");
setInviteCode("");
setInviteFrom("");
setInviteSession("");
}}
onClose={() => updateContext({ invitedTo: undefined })}
/>
)}

{selectedSession && watchingToken && <PlayView selectedToken={watchingToken} />}
{selectedSession && !watchingToken && selectedToken && (
<PlayView selectedToken={selectedToken} />
)}
</>
);
};
Expand Down
29 changes: 25 additions & 4 deletions web/src/components/TitleScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,34 @@ import Playing from "./Playing";
import SignUpForm from "./account/SignUpForm";
import LoginForm from "./account/LoginForm";

import { FULLCOUNT_ASSETS, FULLCOUNT_ASSETS_PATH } from "../constants";
import { FULLCOUNT_ASSETS } from "../constants";
import LoadingView from "./HomePage/LoadingView";
import LaunchForm from "./LaunchForm";
import MoonstreamLogo2 from "./icons/MoonstreamLogo2";
import { useGameContext } from "../contexts/GameContext";
import { useRouter } from "next/router";

const TitleScreen = () => {
const { user, isLoading } = useUser();
const router = useRouter();
const [isLogging, setIsLogging] = useState(false); // login or signUp
const [isSuccess, setIsSuccess] = useState(false);
const [isFirstSeconds, setIsFirstSeconds] = useState(true);
const { isLaunching, updateContext } = useGameContext();

const [inviteFrom, setInviteFrom] = useState("");

useEffect(() => {
if (
router.isReady &&
router.query.invite_from &&
typeof router.query.invite_from === "string"
) {
setInviteFrom(router.query.invite_from);
setIsLogging(true);
}
}, [router.isReady, router.query]);

useEffect(() => {
setTimeout(() => setIsFirstSeconds(false), 2000);
}, []);
Expand All @@ -40,14 +55,20 @@ const TitleScreen = () => {
src={`${FULLCOUNT_ASSETS}/banners/Bl-banner-updated-logo.jpeg`}
alt={""}
/>
{isLaunching ? (
{isLaunching && !inviteFrom ? (
<LaunchForm onClose={() => updateContext({ isLaunching: false })} />
) : (
<>
{!isLogging ? (
<SignUpForm setIsSuccess={(value) => setIsSuccess(value)} />
<SignUpForm
inviteFrom={inviteFrom}
setIsSuccess={(value) => setIsSuccess(value)}
/>
) : (
<LoginForm setIsSuccess={(value) => setIsSuccess(value)} />
<LoginForm
inviteFrom={inviteFrom}
setIsSuccess={(value) => setIsSuccess(value)}
/>
)}
{!isSuccess && (
<div className={styles.footer}>
Expand Down
11 changes: 11 additions & 0 deletions web/src/components/account/Account.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@
opacity: 0;
transition: opacity 1s ease-out;
}

.invitePrompt {
color: #262019;
text-align: center;
font-family: Pangolin, cursive;
font-size: 14px;
font-style: normal;
font-weight: 700;
line-height: normal;
margin-bottom: 20px;
}
16 changes: 14 additions & 2 deletions web/src/components/account/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { Spinner } from "@chakra-ui/react";
import styles from "./Account.module.css";
import useLogin from "../../hooks/useLogin";

const LoginForm = ({ setIsSuccess }: { setIsSuccess: (isSuccess: boolean) => void }) => {
const LoginForm = ({
setIsSuccess,
inviteFrom,
}: {
setIsSuccess: (isSuccess: boolean) => void;
inviteFrom?: string;
}) => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const { login, isLoading, isSuccess } = useLogin();
Expand All @@ -30,7 +36,13 @@ const LoginForm = ({ setIsSuccess }: { setIsSuccess: (isSuccess: boolean) => voi
return (
<form onSubmit={handleSubmit} className={styles.container}>
{/*<div className={`${styles.container} ${isSuccess ? styles.fadeOut : ""}`}>*/}
<div className={`${styles.header} ${isSuccess ? styles.fadeOut : ""}`}>Welcome back!</div>
{inviteFrom ? (
<div className={styles.invitePrompt}>
{`${inviteFrom} is inviting you to play Fullcount.xyz.`}
</div>
) : (
<div className={`${styles.header} ${isSuccess ? styles.fadeOut : ""}`}>Welcome back!</div>
)}
<label className={styles.label}>Username</label>
<input
type="text"
Expand Down
16 changes: 14 additions & 2 deletions web/src/components/account/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { Spinner } from "@chakra-ui/react";
import useSignUp from "../../hooks/useSignUp";
import styles from "./Account.module.css";

const SignUpForm = ({ setIsSuccess }: { setIsSuccess: (isSuccess: boolean) => void }) => {
const SignUpForm = ({
setIsSuccess,
inviteFrom,
}: {
setIsSuccess: (isSuccess: boolean) => void;
inviteFrom?: string;
}) => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [email, setEmail] = useState("");
Expand All @@ -32,7 +38,13 @@ const SignUpForm = ({ setIsSuccess }: { setIsSuccess: (isSuccess: boolean) => vo
return (
<form onSubmit={handleSubmit} className={styles.container}>
{/*<div className={`${styles.container} ${isSuccess ? styles.fadeOut : ""}`}>*/}
<div className={styles.header}>Welcome!</div>
{inviteFrom ? (
<div className={styles.invitePrompt}>
{`${inviteFrom} is inviting you to play Fullcount.xyz.`}
</div>
) : (
<div className={`${styles.header} ${isSuccess ? styles.fadeOut : ""}`}>Welcome!</div>
)}
<label className={styles.label}>Username</label>
<input
type="text"
Expand Down
16 changes: 16 additions & 0 deletions web/src/components/atbat/AtBatView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@
height: 98px;
}

.invitePrompt {
color: #262019;
position: absolute;
right: 50%;
transform: translateX(50%);
z-index: 3;
text-align: center;
font-family: Bangers, cursive;
font-style: normal;
font-weight: 400;
line-height: normal;
top: 88.5px;
font-size: 24px;
width: 320px;
}

.negativeOutcome2 {
stroke: #CD7676;
color: #CD7676;
Expand Down
25 changes: 20 additions & 5 deletions web/src/components/atbat/AtBatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ExitDialog from "./ExitDialog";
import useUser from "../../contexts/UserContext";
import { fetchFullcountPlayerTokens } from "../../tokenInterfaces/FullcountPlayerAPI";
import { useSound } from "../../hooks/useSound";
import InviteLinkView from "./InviteLinkView";

export const outcomes = [
"In Progress",
Expand Down Expand Up @@ -238,7 +239,7 @@ const AtBatView: React.FC = () => {
</div>
)}

{atBatState.data && !isBigView && (
{atBatState.data && !isBigView && atBatState.data.atBat.pitches[0].progress !== 2 && (
<Score
atBat={atBatState.data.atBat}
pitch={atBatState.data.atBat.pitches[currentSessionIdx]}
Expand All @@ -247,7 +248,8 @@ const AtBatView: React.FC = () => {
{atBatState.data &&
isBigView &&
atBatState.data?.atBat.outcome === 0 &&
!showPitchOutcome && (
!showPitchOutcome &&
atBatState.data.atBat.pitches[0].progress !== 2 && (
<ScoreForDesktop
atBat={atBatState.data.atBat}
pitch={atBatState.data.atBat.pitches[currentSessionIdx]}
Expand Down Expand Up @@ -294,6 +296,16 @@ const AtBatView: React.FC = () => {
: "you lose!"}
</div>
)}
{atBatState.data && atBatState.data.atBat.pitches[0].progress === 2 && (
<>
<div className={styles.invitePrompt}>
Waiting for Opponent.
<br />
Invite Friend?
</div>
<InviteLinkView atBat={atBatState.data.atBat} />
</>
)}
{atBatState.data?.atBat.outcome === 0 &&
!showPitchOutcome &&
atBatState.data.atBat.pitches[atBatState.data.atBat.numberOfSessions - 1].progress !== 2 &&
Expand Down Expand Up @@ -338,9 +350,12 @@ const AtBatView: React.FC = () => {
)}
</>
)}
{atBatState.data && !showPitchOutcome && !isBigView && (
<AtBatFooter atBat={atBatState.data.atBat} />
)}
{atBatState.data &&
!showPitchOutcome &&
!isBigView &&
atBatState.data.atBat.pitches[0].progress !== 2 && (
<AtBatFooter atBat={atBatState.data.atBat} />
)}
</div>
);
};
Expand Down
Loading
Loading