Skip to content

Commit

Permalink
Client:Implemented the new modal changes in current modals
Browse files Browse the repository at this point in the history
This commits updates the existing modals to use
the update function if necessary and passes id
for every modal.

Fixes #168
  • Loading branch information
ritwik-69 committed Jun 28, 2024
1 parent f034315 commit 10c0c9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/src/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const Navbar: React.FC = () => {
size="medium"
fontSize="text-2xl"
onClick={() => {
modal.show(aboutUs, 'large', [
modal.show("aboutUsModal",aboutUs, 'large', [
{
text: 'Close',
type: 'submit',
Expand All @@ -260,7 +260,7 @@ const Navbar: React.FC = () => {
size="medium"
fontSize="text-2xl"
onClick={() => {
modal.show(rules, 'large', [
modal.show("rulesModal",rules, 'large', [
{
text: 'Close',
type: 'submit',
Expand Down
33 changes: 28 additions & 5 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useGameContext } from '../contexts/GameContext';
import Button from '../library/button';
import { useModal } from '../library/modal/ModalContext';
Expand Down Expand Up @@ -61,8 +61,23 @@ function Game() {
const navigate = useNavigate();
const [FirstUser, setFirstUser] = useState(true);
const modal = useModal();
const initialMount = useRef(true);
useEffect(() => {
modal.show(<GamePropertiesModal />, 'large', [], false);
if (initialMount.current) {
modal.show(
'gameModal',
<GamePropertiesModal playerCount={gameState.players.length} />,
'large',
[],
false
);
initialMount.current = false;
} else {
modal.updateContent(
'gameModal',
<GamePropertiesModal playerCount={gameState.players.length} />
);
}
// eslint-disable-next-line
}, [gameState.players.length, gameState.id]); // todo add the required dependencies
const drawCard = () => {
Expand Down Expand Up @@ -102,7 +117,7 @@ function Game() {
modal.hide();
}

function GamePropertiesModal() {
function GamePropertiesModal({ playerCount }: { playerCount: number }) {
const currentUser = getUser();
const isHost =
currentUser &&
Expand Down Expand Up @@ -135,7 +150,7 @@ function Game() {
<h2 className="text-bold font-bold text-[#333] font-[Kavoon] text-[20px]">
Players Joined :{' '}
<span className="text-[#555] font-[Roboto]">
{gameState.players.length}
{playerCount}
</span>
</h2>
</div>
Expand Down Expand Up @@ -283,7 +298,15 @@ function Game() {
<button
className="fixed bottom-5 left-5 p-3 bg-lime-500 text-gray-700 rounded-full focus:outline-none transform transition-transform duration-300 hover:scale-105 hover:bg-lime-400 active:bg-lime-600 shadow-md"
onClick={() =>
modal.show(<GamePropertiesModal />, 'large', [], false)
modal.show(
'gameModal',
<GamePropertiesModal
playerCount={gameState.players.length}
/>,
'large',
[],
false
)
}
>
<IoSettings className="w-7 h-7" />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Home() {

const JoinGame = () => {
// Logic to join a game
modal.show(<JoinGameModalContent />, 'small');
modal.show('joinModal', <JoinGameModalContent />, 'small');
console.log('Join Game with code');
};

Expand Down

0 comments on commit 10c0c9c

Please sign in to comment.