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

Add formats to create game form #125

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/app/_components/HomePage/HomePagePlayMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const HomePagePlayMode: React.FC = () => {
</TabPanel>
}
<TabPanel index={user ? 1 : 0} value={value}>
<CreateGameForm format={'Premier'} />
<CreateGameForm />
</TabPanel>
{showTestGames &&
<TabPanel index={2} value={value}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,14 @@ import {
DeckValidationFailureReason,
IDeckValidationFailures
} from '@/app/_validators/DeckValidation/DeckValidationTypes';

interface ICreateGameFormProps {
format?: string | null;
setFormat?: (format: string) => void;
}
import { SwuGameFormat, FormatLabels } from '@/app/_constants/constants';

const deckOptions: string[] = [
'Order66',
'ThisIsTheWay',
];

const formatOptions: string[] = ['Premier'];

const CreateGameForm: React.FC<ICreateGameFormProps> = ({
format,
setFormat,
}) => {
const CreateGameForm = () => {
const pathname = usePathname();
const router = useRouter();
const isCreateGamePath = pathname === '/creategame';
Expand All @@ -47,6 +38,10 @@ const CreateGameForm: React.FC<ICreateGameFormProps> = ({
const [deckLink, setDeckLink] = useState<string>('');
const [saveDeck, setSaveDeck] = useState<boolean>(false);
const [errorModalOpen, setErrorModalOpen] = useState(false);
const savedFormat = localStorage.getItem('format') || SwuGameFormat.Premier;
const [format, setFormat] = useState<string>(savedFormat);

const formatOptions = Object.values(SwuGameFormat);

// For a short, user-friendly error message
const [deckErrorSummary, setDeckErrorSummary] = useState<string | null>(null);
Expand All @@ -58,6 +53,11 @@ const CreateGameForm: React.FC<ICreateGameFormProps> = ({
const [gameName, setGameName] = useState<string>('');
const [privacy, setPrivacy] = useState<string>(user ? 'Public' : 'Private');

const handleChangeFormat = (format: SwuGameFormat) => {
localStorage.setItem('format', format);
setFormat(format);
}

// Handle Create Game Submission
const handleCreateGameSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand All @@ -84,6 +84,7 @@ const CreateGameForm: React.FC<ICreateGameFormProps> = ({
user: user || sessionStorage.getItem('anonymousUserId'),
deck: deckData,
isPrivate: privacy === 'Private',
format: format,
};
const response = await fetch(`${process.env.NEXT_PUBLIC_ROOT_URL}/api/create-lobby`,
{
Expand Down Expand Up @@ -257,14 +258,14 @@ const CreateGameForm: React.FC<ICreateGameFormProps> = ({
<StyledTextField
select
value={format}
required
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFormat ? setFormat(e.target.value) : null
handleChangeFormat(e.target.value as SwuGameFormat)
}
required
>
{formatOptions.map((fmt) => (
<MenuItem key={fmt} value={fmt}>
{fmt}
{FormatLabels[fmt] || fmt}
</MenuItem>
))}
</StyledTextField>
Expand Down
14 changes: 13 additions & 1 deletion src/app/_constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ export enum MatchType {
Custom = 'Custom',
Private = 'Private',
Quick = 'Quick',
}
}

export enum SwuGameFormat {
Premier = 'premier',
NextSetPreview = 'nextSetPreview',
Open = 'open'
}

export const FormatLabels: Record<SwuGameFormat, string> = {
[SwuGameFormat.Premier]: 'Premier',
[SwuGameFormat.NextSetPreview]: 'Next Set Preview',
[SwuGameFormat.Open]: 'Open',
};
Loading