Skip to content

Commit

Permalink
#Public games
Browse files Browse the repository at this point in the history
- Made it so quickgames and public games are available to anon users. Some details could use a little polish.
  • Loading branch information
CheBato committed Feb 27, 2025
1 parent 1dd6271 commit 55d8e63
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
12 changes: 5 additions & 7 deletions src/app/_components/HomePage/HomePagePlayMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ const HomePagePlayMode: React.FC = () => {
<CardContent>
<Box sx={{ borderBottom: 1, borderColor: 'divider', mb: '1rem' }}>
<Tabs value={value} variant="fullWidth" onChange={handleChange}>
{user && <Tab sx={styles.tabStyles} label="Play" />}
<Tab sx={styles.tabStyles} label="Play" />
<Tab sx={styles.tabStyles} label="Create" />
{showTestGames && <Tab sx={styles.tabStyles} label="Test" />}
</Tabs>
</Box>
{user &&
<TabPanel index={0} value={value}>
<QuickGameForm/>
</TabPanel>
}
<TabPanel index={user ? 1 : 0} value={value}>
<TabPanel index={0} value={value}>
<QuickGameForm/>
</TabPanel>
<TabPanel index={1} value={value}>
<CreateGameForm />
</TabPanel>
{showTestGames &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -283,7 +284,7 @@ const CreateGameForm = () => {
value: string
) => setPrivacy(value)}
>
{user && <FormControlLabel
<FormControlLabel
value="Public"
control={<Radio sx={styles.checkboxStyle} />}
label={
Expand All @@ -292,7 +293,6 @@ const CreateGameForm = () => {
</Typography>
}
/>
}
<FormControlLabel
value="Private"
control={<Radio sx={styles.checkboxStyle} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const QuickGameForm: React.FC<ICreateGameFormProps> = () => {
}
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`,
Expand Down Expand Up @@ -138,24 +139,25 @@ const QuickGameForm: React.FC<ICreateGameFormProps> = () => {
</Typography>
<form onSubmit={handleJoinGameQueue}>
{/* Favourite Decks Input */}
<FormControl fullWidth sx={styles.formControlStyle}>
<Typography variant="body1" sx={styles.labelTextStyle}>Favourite Decks</Typography>
<StyledTextField
select
value={favouriteDeck}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFavouriteDeck(e.target.value)
}
placeholder="Vader Green Ramp"
>
{deckOptions.map((deck) => (
<MenuItem key={deck} value={deck}>
{deck}
</MenuItem>
))}
</StyledTextField>
</FormControl>

{user &&
<FormControl fullWidth sx={styles.formControlStyle}>
<Typography variant="body1" sx={styles.labelTextStyle}>Favourite Decks</Typography>
<StyledTextField
select
value={favouriteDeck}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFavouriteDeck(e.target.value)
}
placeholder="Vader Green Ramp"
>
{deckOptions.map((deck) => (
<MenuItem key={deck} value={deck}>
{deck}
</MenuItem>
))}
</StyledTextField>
</FormControl>
}
{/* Deck Link Input */}
<FormControl fullWidth sx={{ mb: 0 }}>
<Box sx={styles.labelTextStyle}>
Expand All @@ -166,10 +168,10 @@ const QuickGameForm: React.FC<ICreateGameFormProps> = () => {
<Link href="https://www.swudb.com/" target="_blank" sx={{ color: 'lightblue' }}>
SWUDB
</Link>{' '}
or{' '}
{/* or{' '}
<Link href="https://www.sw-unlimited-db.com/" target="_blank" sx={{ color: 'lightblue' }}>
SW-Unlimited-DB
</Link>{' '}
</Link>{' '} */}
Deck Link{' '}
<Typography variant="body1" sx={styles.labelTextStyleSecondary}>
(use the URL or &apos;Deck Link&apos; button)
Expand Down Expand Up @@ -197,7 +199,7 @@ const QuickGameForm: React.FC<ICreateGameFormProps> = () => {
)}
</FormControl>

{/* Save Deck To Favourites Checkbox */}
{/* Save Deck To Favourites Checkbox
<FormControlLabel
sx={{ mb: '1rem' }}
control={
Expand All @@ -216,6 +218,7 @@ const QuickGameForm: React.FC<ICreateGameFormProps> = () => {
</Typography>
}
/>
*/}

{/* Submit Button */}
<Button type="submit" disabled={queueState} variant="contained" sx={{ ...styles.submitButtonStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/app/_contexts/Game.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const GameProvider = ({ children }: { children: ReactNode }) => {
const newSocket = io(`${process.env.NEXT_PUBLIC_ROOT_URL}`, {
path: '/ws',
query: {
user: JSON.stringify(user ? user : { username: '', id: anonymousUserId }),
user: JSON.stringify(user ? user : { username: 'anonymousUser'+anonymousUserId?.substring(0,6), id: anonymousUserId }),
lobby: JSON.stringify({ lobbyId:lobbyId ? lobbyId : null })
},
});
Expand Down

0 comments on commit 55d8e63

Please sign in to comment.