From 558be58fe1f8ec5383d9866d073b12993ad0457b Mon Sep 17 00:00:00 2001 From: Selvio Perez Date: Tue, 10 Dec 2024 13:48:24 -0500 Subject: [PATCH 1/2] Force login to join game --- src/components/InitialView/InitialView.tsx | 26 +++++++++++++++++----- src/components/LoginModal/LoginModal.tsx | 11 +++++++-- src/context/AppContextProvider.tsx | 6 +++-- src/context/useAppContext.ts | 10 +++++---- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/components/InitialView/InitialView.tsx b/src/components/InitialView/InitialView.tsx index e12b159..003fad1 100644 --- a/src/components/InitialView/InitialView.tsx +++ b/src/components/InitialView/InitialView.tsx @@ -17,20 +17,22 @@ interface InitialViewProps { const InitialView: FC = ({ startGame }) => { const { - setGameData, accountData, - isQualified, - setIsQualified, isLoadingUserData, + isQualified, + isUserDataFetched, + keys, setAccountData, + setGameData, + setIsQualified, } = useAppContext(); + const { publicKeyHashHex } = keys || {}; const [, setSessionId] = useSessionIdKeyCache(); const pathSegments = window.location.hash.split("/").filter(Boolean); const code = pathSegments[2]; const [modalTitle, _] = useState("Join Multiplayer"); - const [isNameModalOpen, setIsNameModalOpen] = useState( - pathSegments[1] === EGameType.JOIN, - ); + const [isNameModalOpen, setIsNameModalOpen] = useState(false); + const isJoin = pathSegments[1] === EGameType.JOIN; const [isWelcomeModalOpen, setIsWelcomeModalOpen] = useState(false); const [isLoginModalOpen, setIsLoginModalOpen] = useState(false); @@ -42,6 +44,16 @@ const InitialView: FC = ({ startGame }) => { } }, [code, setGameData]); + useEffect(() => { + if (isJoin && publicKeyHashHex && !isLoadingUserData) { + if (isUserDataFetched) { + setIsNameModalOpen(true); + } else { + setIsLoginModalOpen(true); + } + } + }, [isLoadingUserData, isUserDataFetched, isJoin, publicKeyHashHex]); + const handleTournamentLogin = () => { setIsLoginModalOpen(true); }; @@ -188,7 +200,9 @@ const InitialView: FC = ({ startGame }) => { /> setIsLoginModalOpen(false)} + isJoin={isJoin} isOpen={isLoginModalOpen} + openNameModal={() => setIsNameModalOpen(true)} showActionButtons={showActionButtons} /> diff --git a/src/components/LoginModal/LoginModal.tsx b/src/components/LoginModal/LoginModal.tsx index 28ebf8e..d01719c 100644 --- a/src/components/LoginModal/LoginModal.tsx +++ b/src/components/LoginModal/LoginModal.tsx @@ -26,7 +26,9 @@ import { checkSignin, fetchAuthProviders } from "../../utils/requests"; interface LoginModalProps { close: () => void; + isJoin: boolean; isOpen: boolean; + openNameModal: () => void; showActionButtons: () => void; } @@ -77,7 +79,9 @@ const CheckBoxInput: FC<{ const LoginModal: React.FC = ({ close, + isJoin, isOpen, + openNameModal, showActionButtons, }) => { const shouldShowAllTou = Date.now() >= 1733238000000; @@ -120,14 +124,17 @@ const LoginModal: React.FC = ({ if (account) setAccountData(account); if (session?.session_id) setSessionId(session.session_id); if (qualifier) setIsQualified(qualifier.is_qualified); + if (isJoin) openNameModal(); } }, [ close, + isJoin, + openNameModal, setAccountData, + setIsQualified, setSessionId, showActionButtons, userData, - setIsQualified, ]); const handleClose = () => { @@ -154,7 +161,7 @@ const LoginModal: React.FC = ({ const renderConsentContent = () => { return (
-

Tournament Consent

+

Tournament Consent

{shouldShowAllTou ? ( <> {/** diff --git a/src/context/AppContextProvider.tsx b/src/context/AppContextProvider.tsx index 688814d..c3d3748 100644 --- a/src/context/AppContextProvider.tsx +++ b/src/context/AppContextProvider.tsx @@ -82,18 +82,19 @@ const AppContextProvider: FC = ({ children }) => { bots, gameData, globalStats, + isUserDataFetched: !!(userData || accountData), isLoadingGlobalStats, isLoadingUserData, + isQualified, keys, players, region, setAccountData, setBots, setGameData, + setIsQualified, setPlayers, setRegion, - isQualified, - setIsQualified, }), [ accountData, @@ -107,6 +108,7 @@ const AppContextProvider: FC = ({ children }) => { players, region, isQualified, + userData, ], ); diff --git a/src/context/useAppContext.ts b/src/context/useAppContext.ts index d30cc95..935da39 100644 --- a/src/context/useAppContext.ts +++ b/src/context/useAppContext.ts @@ -14,18 +14,19 @@ interface AppContextInterface { bots: number; gameData: GameData; globalStats?: GameStatistics; + isUserDataFetched: boolean; isLoadingGlobalStats: boolean; isLoadingUserData: boolean; + isQualified: boolean; keys: Keys | null; players: number; region: Region | null; - isQualified: boolean; setAccountData: Dispatch>; setBots: Dispatch>; setGameData: Dispatch>; + setIsQualified: Dispatch>; setPlayers: Dispatch>; setRegion: Dispatch>; - setIsQualified: Dispatch>; } export const AppContext = createContext({ @@ -34,18 +35,19 @@ export const AppContext = createContext({ bots: 1, gameData: { petName: "", code: "", type: EGameType.SOLO }, globalStats: undefined, + isUserDataFetched: false, isLoadingGlobalStats: false, isLoadingUserData: false, + isQualified: false, keys: null, players: 1, region: null, - isQualified: false, setAccountData: () => {}, setBots: () => {}, setGameData: () => {}, + setIsQualified: () => {}, setPlayers: () => {}, setRegion: () => {}, - setIsQualified: () => {}, }); export const useAppContext = () => { From 61585a94fec4344287c0778b61ba89086fdf3922 Mon Sep 17 00:00:00 2001 From: Pi Lanningham Date: Tue, 10 Dec 2024 13:56:40 -0500 Subject: [PATCH 2/2] Update src/components/InitialView/InitialView.tsx Co-authored-by: Calvin --- src/components/InitialView/InitialView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/InitialView/InitialView.tsx b/src/components/InitialView/InitialView.tsx index 003fad1..fd62ec0 100644 --- a/src/components/InitialView/InitialView.tsx +++ b/src/components/InitialView/InitialView.tsx @@ -26,7 +26,7 @@ const InitialView: FC = ({ startGame }) => { setGameData, setIsQualified, } = useAppContext(); - const { publicKeyHashHex } = keys || {}; +const publicKeyHashHex = keys?.publicKeyHashHex const [, setSessionId] = useSessionIdKeyCache(); const pathSegments = window.location.hash.split("/").filter(Boolean); const code = pathSegments[2];