From 55d8e633e9507ac52b8375aa4a6dadab89a260ae Mon Sep 17 00:00:00 2001 From: matevz Date: Thu, 27 Feb 2025 17:20:26 +0100 Subject: [PATCH] #Public games - Made it so quickgames and public games are available to anon users. Some details could use a little polish. --- .../_components/HomePage/HomePagePlayMode.tsx | 12 ++--- .../JoinableGame/JoinableGame.tsx | 8 +++- .../CreateGameForm/CreateGameForm.tsx | 6 +-- .../QuickGameForm/QuickGameForm.tsx | 47 ++++++++++--------- src/app/_contexts/Game.context.tsx | 2 +- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/app/_components/HomePage/HomePagePlayMode.tsx b/src/app/_components/HomePage/HomePagePlayMode.tsx index a8b6a9c0..f9dc54ca 100644 --- a/src/app/_components/HomePage/HomePagePlayMode.tsx +++ b/src/app/_components/HomePage/HomePagePlayMode.tsx @@ -82,17 +82,15 @@ const HomePagePlayMode: React.FC = () => { - {user && } + {showTestGames && } - {user && - - - - } - + + + + {showTestGames && diff --git a/src/app/_components/HomePage/_subcomponents/JoinableGame/JoinableGame.tsx b/src/app/_components/HomePage/_subcomponents/JoinableGame/JoinableGame.tsx index e8867994..8787e09e 100644 --- a/src/app/_components/HomePage/_subcomponents/JoinableGame/JoinableGame.tsx +++ b/src/app/_components/HomePage/_subcomponents/JoinableGame/JoinableGame.tsx @@ -31,13 +31,19 @@ const JoinableGame: React.FC = () => { }, []); const joinLobby = async (lobbyId: string) => { + // we need to set the user try { + const payload = { + lobbyId: lobbyId, + user: { id: user?.id || sessionStorage.getItem('anonymousUserId'), + username:user?.username || 'anonymousUser'+sessionStorage.getItem('anonymousUserId')?.substring(0,6) }, + }; const response = await fetch(`${process.env.NEXT_PUBLIC_ROOT_URL}/api/join-lobby`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ lobbyId, user }), + body: JSON.stringify(payload), }); if (!response.ok) { diff --git a/src/app/_components/_sharedcomponents/CreateGameForm/CreateGameForm.tsx b/src/app/_components/_sharedcomponents/CreateGameForm/CreateGameForm.tsx index 6d98b5c0..28200b8e 100644 --- a/src/app/_components/_sharedcomponents/CreateGameForm/CreateGameForm.tsx +++ b/src/app/_components/_sharedcomponents/CreateGameForm/CreateGameForm.tsx @@ -81,7 +81,8 @@ const CreateGameForm = () => { } try { const payload = { - user: user || sessionStorage.getItem('anonymousUserId'), + user: { id: user?.id || sessionStorage.getItem('anonymousUserId'), + username:user?.username || 'anonymousUser'+sessionStorage.getItem('anonymousUserId')?.substring(0,6) }, deck: deckData, isPrivate: privacy === 'Private', format: format, @@ -283,7 +284,7 @@ const CreateGameForm = () => { value: string ) => setPrivacy(value)} > - {user && } label={ @@ -292,7 +293,6 @@ const CreateGameForm = () => { } /> - } } diff --git a/src/app/_components/_sharedcomponents/QuickGameForm/QuickGameForm.tsx b/src/app/_components/_sharedcomponents/QuickGameForm/QuickGameForm.tsx index 6f142506..72f1fd78 100644 --- a/src/app/_components/_sharedcomponents/QuickGameForm/QuickGameForm.tsx +++ b/src/app/_components/_sharedcomponents/QuickGameForm/QuickGameForm.tsx @@ -63,7 +63,8 @@ const QuickGameForm: React.FC = () => { } try { const payload = { - user: user, + user: { id: user?.id || sessionStorage.getItem('anonymousUserId'), + username:user?.username || 'anonymousUser'+sessionStorage.getItem('anonymousUserId')?.substring(0,6) }, deck: deckData, }; const response = await fetch(`${process.env.NEXT_PUBLIC_ROOT_URL}/api/enter-queue`, @@ -138,24 +139,25 @@ const QuickGameForm: React.FC = () => {
{/* Favourite Decks Input */} - - Favourite Decks - ) => - setFavouriteDeck(e.target.value) - } - placeholder="Vader Green Ramp" - > - {deckOptions.map((deck) => ( - - {deck} - - ))} - - - + {user && + + Favourite Decks + ) => + setFavouriteDeck(e.target.value) + } + placeholder="Vader Green Ramp" + > + {deckOptions.map((deck) => ( + + {deck} + + ))} + + + } {/* Deck Link Input */} @@ -166,10 +168,10 @@ const QuickGameForm: React.FC = () => { SWUDB {' '} - or{' '} + {/* or{' '} SW-Unlimited-DB - {' '} + {' '} */} Deck Link{' '} (use the URL or 'Deck Link' button) @@ -197,7 +199,7 @@ const QuickGameForm: React.FC = () => { )} - {/* Save Deck To Favourites Checkbox */} + {/* Save Deck To Favourites Checkbox = () => { } /> + */} {/* Submit Button */}