-
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 ab9fc28
Showing
2 changed files
with
83 additions
and
1 deletion.
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 |
---|---|---|
@@ -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