Skip to content

Commit

Permalink
Add a join game modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeinzer committed May 8, 2020
1 parent a2c83e9 commit 1ac1939
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 10 deletions.
7 changes: 6 additions & 1 deletion definitely-not-codenames/src/actions/modalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ const setSendRoomModal = (isOpen) => ({
isOpen,
});

export {setSendRoomModal};
const setJoinRoomModal = (isOpen) => ({
type: 'SET_JOIN_ROOM_MODAL',
isOpen,
});

export {setSendRoomModal, setJoinRoomModal};
2 changes: 1 addition & 1 deletion definitely-not-codenames/src/components/GameEndModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const GameEndModal = () => {
type="button"
onClick={handleCloseModal}
>
X
</button>
<h2 className="modal__title--winner">Winner!</h2>
<h2 className="modal__title--winner">{`${mode}`}</h2>
Expand Down
1 change: 0 additions & 1 deletion definitely-not-codenames/src/components/GamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import HintContainer from './HintContainer';
import GameEndModal from './GameEndModal';
import {gameStartedSelector} from '../selectors/gameSelectors';
import SendRoomModal from './SendRoomModal';
import SendRoomModalButton from './SendRoomModalButton';

const GamePage = () => {
const {roomID} = useParams();
Expand Down
4 changes: 3 additions & 1 deletion definitely-not-codenames/src/components/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import RequestRoom from './RequestRoom';
import JoinRoom from './JoinRoom';
import GameCardDisabled from './GameCardDisabled';
import CARDS from '../constants/homePage';
import JoinRoomModal from './JoinRoomModal';

const HomePage = () => {
return (
<div>
<JoinRoomModal />
<div className="hint WHITE">
<p className="hint__home-page-title">Codenames</p>
</div>
<div className="game-grid__container">
{CARDS.map((card, i) => {
switch (i) {
case 11:
case 11: // The card index
return <RequestRoom />;
case 13:
return <JoinRoom />;
Expand Down
15 changes: 12 additions & 3 deletions definitely-not-codenames/src/components/JoinRoom.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';
import {useHistory} from 'react-router-dom';
import {useDispatch} from 'react-redux';
import {setJoinRoomModal} from '../actions/modalActions';

const JoinRoom = () => {
const history = useHistory();
const dispatch = useDispatch();

const handleJoinRoomClick = () => {
dispatch(setJoinRoomModal(true));
};

return (
<button className="game-grid__card--home-page-button--RED" type="button">
<button
className="game-grid__card--home-page-button--RED"
type="button"
onClick={handleJoinRoomClick}
>
Join Room
</button>
);
Expand Down
63 changes: 63 additions & 0 deletions definitely-not-codenames/src/components/JoinRoomModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, {useState} from 'react';
import {useSelector, useDispatch} from 'react-redux';
import Modal from 'react-modal';
import {useHistory} from 'react-router-dom';
import {NORMAL_TIME} from '../constants/animation';
import {setJoinRoomModal} from '../actions/modalActions';

const JoinRoomModal = () => {
const dispatch = useDispatch();
const history = useHistory();

const isOpen = useSelector((state) => state.modals.joinRoom);

const [gameID, setGameID] = useState('');

const handleGameIDChange = (e) => {
setGameID(e.target.value);
};

const handleGameIDSubmit = (e) => {
e.preventDefault();
history.push(`/game/${gameID}`);
};

const handleCloseModal = () => {
dispatch(setJoinRoomModal(false));
};

return (
<Modal
className="modal modal--TAN"
isOpen={isOpen}
closeTimeoutMS={NORMAL_TIME}
onRequestClose={handleCloseModal}
ariaHideApp={false}
>
<div>
<button
className="modal__close-button"
type="button"
onClick={handleCloseModal}
>
</button>
<form onSubmit={handleGameIDSubmit} className="modal__sub-container">
<h2 className="modal__title">Input Game ID</h2>
<input
className="modal__input--join"
type="text"
onChange={handleGameIDChange}
value={gameID}
autoFocus
/>
<button type="submit" className="modal__button--join">
Join Game
</button>
</form>
</div>
</Modal>
);
};

export default JoinRoomModal;
2 changes: 1 addition & 1 deletion definitely-not-codenames/src/components/SendRoomModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SendRoomModal = () => {
type="button"
onClick={handleCloseModal}
>
X
</button>
<h2 className="modal__title">Send Invite</h2>
<h2 className="modal__sub-title">
Expand Down
2 changes: 1 addition & 1 deletion definitely-not-codenames/src/constants/homePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const cards = [
},
];

const modifiedCards = cards.map((card, i) => {
const modifiedCards = cards.map((card) => {
const newCard = {...card};
newCard.word = '';
if (Math.random() < 0.33) {
Expand Down
4 changes: 4 additions & 0 deletions definitely-not-codenames/src/reducers/modalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import {createReducer} from '@reduxjs/toolkit';

const intialState = {
sendRoom: false,
joinRoom: false,
};

const modalReducer = createReducer(intialState, {
SET_SEND_ROOM_MODAL: (state, action) => {
state.sendRoom = action.isOpen;
},
SET_JOIN_ROOM_MODAL: (state, action) => {
state.joinRoom = action.isOpen;
},
});

export default modalReducer;
15 changes: 14 additions & 1 deletion definitely-not-codenames/src/styles/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
}
}

.modal__button--join {
@extend .modal__button;
background-color: $light-tan;
color: black;
width: 10rem;
}

.modal__close-button {
background-color: unset;
border: none;
Expand All @@ -129,7 +136,7 @@
position: absolute;
top: 50%;
left: 50%;
transform: translate(13rem, -9.8rem);
transform: translate(12.8rem, -9.8rem);
}

.modal__input {
Expand All @@ -145,6 +152,12 @@
width: 18rem;
}

.modal__input--join {
@extend .modal__input;
color: black;
border-color: black;
}

.modal__top-left-triangle {
position: absolute;
width: 0;
Expand Down

0 comments on commit 1ac1939

Please sign in to comment.