-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend: JoinExistingGame Modal implementation
JoinExistingGame modal component created to capture room code for game entry. onClose function utilized for modal closure by tapping anywhere on the screen. Navigation to the /game route triggered by pressing the Enter button after input entry; otherwise,a toast prompts for input completion. Fixes #84
- Loading branch information
1 parent
3fda6cc
commit f87e6f8
Showing
14 changed files
with
174 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
node_modules | ||
frontend/node_modules | ||
.DS_Store | ||
.env |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
export type ControllerFunction = (req: Request, res: Response) => Promise<void>; | ||
type ControllerFunction = (req: Request, res: Response) => Promise<void>; | ||
|
||
export function catchError(fn: ControllerFunction): ControllerFunction { | ||
return async function (req: Request, res: Response) { | ||
try { | ||
return await fn(req, res); | ||
} catch (error) { | ||
res.status(500).json({ error: (error as Error).message }); | ||
res.status(500).json({ error: error }); | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { useRef, useState, useContext } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import Button from './button'; | ||
import { ToastContext } from './toast/toast-context'; | ||
|
||
interface ModalProps { | ||
onClose: () => void; | ||
} | ||
|
||
const Modal: React.FC<ModalProps> = ({ onClose }) => { | ||
const modalRef = useRef<HTMLDivElement>(null); | ||
const navigate = useNavigate(); | ||
const [gameCode, setGameCode] = useState(''); | ||
const { open } = useContext(ToastContext); | ||
|
||
const closeModal = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => { | ||
if (modalRef.current === e.target) { | ||
onClose(); | ||
} | ||
}; | ||
|
||
const handleButtonClick = () => { | ||
if (gameCode.trim()) { | ||
navigate('/game'); | ||
} else { | ||
open({ | ||
message: 'Please enter the game code', | ||
duration: 3000, | ||
position: 'top-center', | ||
color: 'warning', | ||
}); | ||
} | ||
}; | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setGameCode(e.target.value); | ||
}; | ||
|
||
return ( | ||
<div | ||
ref={modalRef} | ||
onClick={closeModal} | ||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm flex items-center justify-center" | ||
> | ||
<div className="bg-[rgb(222,209,209)] p-5 rounded-xl border-4 border-black shadow-md flex flex-col gap-4 w-100 items-center"> | ||
<h1 className="font-normal font-[Kavoon] text-[30px] leading-[30px] text-black text-center"> | ||
Join an | ||
<br /> | ||
Existing Game | ||
</h1> | ||
<div className="flex justify-center"> | ||
<input | ||
className="font-normal font-[Kavoon] text-[20px] py-2 px-6 border-4 border-black rounded-3xl w-64 h-10" | ||
placeholder="Enter the game code" | ||
style={{ | ||
backgroundColor: 'rgb(222, 209, 209)', | ||
color: 'black', | ||
}} | ||
value={gameCode} | ||
onChange={handleInputChange} | ||
/> | ||
</div> | ||
<Button | ||
text="Enter" | ||
onClick={handleButtonClick} | ||
backgroundColor="bg-yellow-300" | ||
textColor="text-white" | ||
borderColor="border-black border-4" | ||
hoverColor="hover:bg-yellow-400" | ||
rounded="rounded-full" | ||
buttonSize="w-32 h-10" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.