Skip to content

Commit

Permalink
feat: update login logic for elimination stage
Browse files Browse the repository at this point in the history
  • Loading branch information
yHSJ committed Dec 8, 2024
1 parent 090eee8 commit 1ca1e93
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 22 deletions.
85 changes: 67 additions & 18 deletions src/components/InitialView/InitialView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ interface InitialViewProps {
}

const InitialView: FC<InitialViewProps> = ({ startGame }) => {
const { setGameData, accountData, isLoadingUserData, setAccountData } =
useAppContext();
const {
setGameData,
accountData,
isQualified,
setIsQualified,
isLoadingUserData,
setAccountData,
} = useAppContext();
const [, setSessionId] = useSessionIdKeyCache();
const pathSegments = window.location.hash.split("/").filter(Boolean);
const code = pathSegments[2];
Expand Down Expand Up @@ -48,9 +54,9 @@ const InitialView: FC<InitialViewProps> = ({ startGame }) => {
setGameData((prev) => ({ ...prev, type: EGameType.JOIN }));
};

// const handleTournamentLogin = () => {
// setIsLoginModalOpen(true);
// };
const handleTournamentLogin = () => {
setIsLoginModalOpen(true);
};

const handleSubmitNameModal = () => {
setIsNameModalOpen(false);
Expand All @@ -63,11 +69,10 @@ const InitialView: FC<InitialViewProps> = ({ startGame }) => {

const onLogout = () => {
setAccountData(undefined);
setIsQualified(false);
setSessionId("");
};

console.log(accountData);

const renderButtons = () => {
if (isLoadingUserData) {
return <div className="h-72 flex items-center text-3xl">Loading...</div>;
Expand All @@ -77,16 +82,60 @@ const InitialView: FC<InitialViewProps> = ({ startGame }) => {
return (
<>
{accountData ? (
<div className="flex items-center gap-6 justify-center mb-8">
<div className="text-3xl">
Logged In as:{" "}
<span className="text-white text-shadow-custom">
{accountData.auth_name}
</span>
<div className="flex-col">
<div className="flex items-center gap-6 justify-center mb-8">
<div className="text-3xl">
Logged In as:{" "}
<span className="text-white text-shadow-custom">
{accountData.auth_name}
</span>
</div>
<Button className="text-xl w-36 h-11" onClick={onLogout} tick>
Logout
</Button>
</div>
<Button className="text-xl w-36 h-11" onClick={onLogout} tick>
Logout
</Button>
{!isQualified ? (
<>
<div className="flex items-center gap-6 justify-center mb-8">
<span className="text-white text-3xl text-shadow-custom">
Unfortunately, you have not qualified for the next stage
of the tournament.
</span>
</div>
<div className="text-center text-5xl mb-8">Free Play</div>
</>
) : (
<div className="flex-col items-center gap-6 justify-center text-center mb-8">
<div className="text-white text-3xl text-shadow-custom">
Congratulations, you've qualified! Your next steps:
</div>
<div className="text-white text-3xl text-shadow-custom">
1) Connect your Discord to your tournament account{" "}
<a
target="_blank"
href="https://rewardengine.dripdropz.io/leaderboard/d93212b3-dbdc-40d0-befd-f90508c6232d"
className="text-black hover:text-red-800"
>
here
</a>
</div>
<div className="text-white text-3xl text-shadow-custom">
2) Join our{" "}
<a
target="_blank"
href="https://discord.gg/DBEUycQm7F"
className="text-black hover:text-red-800"
>
Discord server
</a>{" "}
for matchmaking & more information
</div>

<div className="mt-8 text-center text-5xl mb-8">
Free Play
</div>
</div>
)}
</div>
) : (
<div className="text-center text-5xl mb-8">Free Play</div>
Expand All @@ -103,11 +152,11 @@ const InitialView: FC<InitialViewProps> = ({ startGame }) => {

return (
<>
{/* {Date.now() > 1733238000000 && (
{Date.now() > 1733620395000 && ( //1733666400000
<Button className="w-96 h-16" onClick={handleTournamentLogin}>
Tournament Login
</Button>
)} */}
)}
<Button className="w-96 h-16" onClick={showActionButtons}>
Free Play
</Button>
Expand Down
14 changes: 11 additions & 3 deletions src/components/LoginModal/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const LoginModal: React.FC<LoginModalProps> = ({
}) => {
const shouldShowAllTou = Date.now() >= 1733238000000;
const [, setSessionId] = useSessionIdKeyCache();
const { keys, setAccountData } = useAppContext();
const { keys, setAccountData, setIsQualified } = useAppContext();
const { publicKeyHashHex } = keys || {};
const [isWaitingSigning, setIsWaitingSigning] = useState(false);
const [tou, setTou] = useState<ITOU>({
Expand Down Expand Up @@ -113,14 +113,22 @@ const LoginModal: React.FC<LoginModalProps> = ({

useEffect(() => {
if (userData?.authenticated) {
const { account, session } = userData;
const { account, session, qualifier } = userData;
setIsWaitingSigning(false);
close();
showActionButtons();
if (account) setAccountData(account);
if (session?.session_id) setSessionId(session.session_id);
if (qualifier) setIsQualified(qualifier.is_qualified);
}
}, [close, setAccountData, setSessionId, showActionButtons, userData]);
}, [
close,
setAccountData,
setSessionId,
showActionButtons,
userData,
setIsQualified,
]);

const handleClose = () => {
if (!isWaitingSigning) {
Expand Down
8 changes: 7 additions & 1 deletion src/context/AppContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AuthResponse,
EGameType,
GameStatistics,
Qualifier,
Region,
} from "../types";
import useBestRegion from "../hooks/useBestRegion";
Expand All @@ -28,6 +29,7 @@ const AppContextProvider: FC<PropsWithChildren> = ({ children }) => {
type: EGameType.SOLO,
});
const [accountData, setAccountData] = useState<Account>();
const [isQualified, setIsQualified] = useState<boolean>(false);
const [region, setRegion] = useState<Region | null>(null);
const [players, setPlayers] = useState(1);
const [bots, setBots] = useState(1);
Expand Down Expand Up @@ -58,9 +60,10 @@ const AppContextProvider: FC<PropsWithChildren> = ({ children }) => {

useEffect(() => {
if (userData) {
const { account, session } = userData;
const { account, session, qualifier } = userData;
if (session?.session_id) setSessionId(session.session_id);
if (account) setAccountData(account);
if (qualifier) setIsQualified(qualifier.is_qualified);
}
}, [setSessionId, userData]);

Expand Down Expand Up @@ -90,6 +93,8 @@ const AppContextProvider: FC<PropsWithChildren> = ({ children }) => {
setGameData,
setPlayers,
setRegion,
isQualified,
setIsQualified,
}),
[
accountData,
Expand All @@ -102,6 +107,7 @@ const AppContextProvider: FC<PropsWithChildren> = ({ children }) => {
keys,
players,
region,
isQualified,
],
);

Expand Down
4 changes: 4 additions & 0 deletions src/context/useAppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ interface AppContextInterface {
keys: Keys | null;
players: number;
region: Region | null;
isQualified: boolean;
setAccountData: Dispatch<React.SetStateAction<Account | undefined>>;
setBots: Dispatch<React.SetStateAction<number>>;
setGameData: Dispatch<React.SetStateAction<GameData>>;
setPlayers: Dispatch<React.SetStateAction<number>>;
setRegion: Dispatch<React.SetStateAction<Region | null>>;
setIsQualified: Dispatch<React.SetStateAction<boolean>>;
}

export const AppContext = createContext<AppContextInterface>({
Expand All @@ -37,11 +39,13 @@ export const AppContext = createContext<AppContextInterface>({
keys: null,
players: 1,
region: null,
isQualified: false,
setAccountData: () => {},
setBots: () => {},
setGameData: () => {},
setPlayers: () => {},
setRegion: () => {},
setIsQualified: () => {},
});

export const useAppContext = () => {
Expand Down
23 changes: 23 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,33 @@ export interface Session {
auth_country_code: string;
authenticated_at: string;
}

export interface Qualifier {
is_qualified: boolean;
rqeuirements: [
{
is_met: boolean;
play_to: string;
play_from: string;
},
{
is_met: boolean;
actual_kill_count: number;
required_kill_count: number;
},
{
is_met: true;
actual_play_minutes: number;
required_play_minutes: number;
},
];
}

export interface AuthResponse {
authenticated: boolean;
account: Account | null;
session: Session | null;
qualifier: Qualifier | null;
}

export interface Keys {
Expand Down

0 comments on commit 1ca1e93

Please sign in to comment.