Skip to content

Commit 6c78827

Browse files
committed
refactor/move login button from header to side window
1 parent 02747a6 commit 6c78827

File tree

13 files changed

+179
-120
lines changed

13 files changed

+179
-120
lines changed

client/src/components/game/game.js

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@ export class Game extends React.Component {
9494

9595
/* spped up on level up */
9696
if ((game.points.level > prevGame.points.level)
97-
&& (game.timerInterval > 100)
98-
&& (!multiPlayer)
97+
&& (game.timerInterval > 100)
98+
&& (!multiPlayer)
9999
) {
100100
Action(LEVEL_UP, 50);
101101
}
102102

103103
/* draws floor or sets state to do so before the next tick */
104104
if (game.rubble.boundaryCells.length > 10
105-
&& prevGame.rubble.boundaryCells.length !== game.rubble.boundaryCells.length) {
105+
&& prevGame.rubble.boundaryCells.length !== game.rubble.boundaryCells.length) {
106106
if (!game.activeShape.cells.length || game.paused) drawFloor(game, this.canvasContextMajor);
107107
else this.setState({ updateFloor: true });
108108
}
109109

110110
/* an Invitation from another client has been accepted */
111111
if (!multiPlayer && socket.temp) {
112112
if (prevSocket.temp && !prevSocket.temp.acceptedInvitation
113-
&& socket.temp.acceptedInvitation) {
113+
&& socket.temp.acceptedInvitation) {
114114
this.setState({ multiPlayer: true }, () => this.resetBoard({ reStart: false }));
115115
}
116116
}
@@ -122,7 +122,7 @@ export class Game extends React.Component {
122122

123123
componentWillUnmount() {
124124
this.endTick('componentWillUnmount');
125-
window.removeEventListener('resize', () => {});
125+
window.removeEventListener('resize', () => { });
126126
}
127127

128128
audioProps = () => {
@@ -347,8 +347,8 @@ export class Game extends React.Component {
347347
const minWidthMP = 800;
348348
if (
349349
(multiPlayer && window.innerWidth < minWidthMP)
350-
|| (!multiPlayer && window.innerWidth < minWidthSP)
351-
|| (window.innerHeight < minHeight)
350+
|| (!multiPlayer && window.innerWidth < minWidthSP)
351+
|| (window.innerHeight < minHeight)
352352
) this.setState({ windowTooSmall: true });
353353
else this.setState({ windowTooSmall: null }, () => this.loadCanvas());
354354
};
@@ -359,34 +359,33 @@ export class Game extends React.Component {
359359
difficulty, multiPlayer, inGameToggle,
360360
buttonPause, floorsRaised, windowTooSmall,
361361
} = this.state;
362-
return(
362+
return (
363363
<div id="landing">
364364
{
365365
Object.keys(game).length && !windowTooSmall ?
366-
<div className="democontainer">
367-
<Controls
368-
minorCanvas={this.canvasMinor}
369-
game={game}
370-
difficulty={difficulty}
371-
socketId={socket.mySocketId}
372-
multiPlayer={[multiPlayer, inGameToggle]}
373-
pauseButtonState={buttonPause}
374-
onReset={b => this.resetBoard({ reStart: b })}
375-
onhandlePause={() => this.handlePause}
376-
onFloorRaise={() => this.floorRaise(1)}
377-
onMultiPlayer={() => this.handleMultiplayer}
378-
allowMultiPlayer={Boolean(Object.keys(socket).length) && socket.usersLoggedIn > 1}
379-
/>
380-
<canvas
381-
ref={this.canvasMajor}
382-
width={game.canvas.canvasMajor.width}
383-
height={game.canvas.canvasMajor.height}
384-
tabIndex="0"
385-
onKeyDown={e => this.gamePlay(e)}
386-
onKeyUp={e => this.arrowKeyLag(e)}
387-
/>
388-
{multiPlayer
389-
? (
366+
<div className="democontainer">
367+
<Controls
368+
minorCanvas={this.canvasMinor}
369+
game={game}
370+
difficulty={difficulty}
371+
socketId={socket.mySocketId}
372+
multiPlayer={[multiPlayer, inGameToggle]}
373+
pauseButtonState={buttonPause}
374+
onReset={b => this.resetBoard({ reStart: b })}
375+
onhandlePause={() => this.handlePause}
376+
onFloorRaise={() => this.floorRaise(1)}
377+
onMultiPlayer={() => this.handleMultiplayer}
378+
allowMultiPlayer={Boolean(Object.keys(socket).length) && socket.usersLoggedIn > 1}
379+
/>
380+
<canvas
381+
ref={this.canvasMajor}
382+
width={game.canvas.canvasMajor.width}
383+
height={game.canvas.canvasMajor.height}
384+
tabIndex="0"
385+
onKeyDown={e => this.gamePlay(e)}
386+
onKeyUp={e => this.arrowKeyLag(e)}
387+
/>
388+
390389
<Opponent
391390
onReset={reStart => this.resetBoard(reStart)}
392391
onFloorRaise={f => this.floorRaise(f)}
@@ -397,13 +396,11 @@ export class Game extends React.Component {
397396
difficulty={difficulty}
398397
floorsRaisedOnOpp={f => this.setState({ floorsRaised: floorsRaised + f })}
399398
/>
400-
)
401-
: null
402-
}
403-
<Audio {...this.audioProps()} />
404-
</div>
405-
:
406-
<div id="smallwindow" />
399+
400+
<Audio {...this.audioProps()} />
401+
</div>
402+
:
403+
<div id="smallwindow" />
407404
}
408405
</div>
409406
)

client/src/components/header/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Header extends React.Component {
120120
}
121121
</React.Fragment>
122122
)
123-
: <div id="authbutton"><button id="login" type="submit" onClick={() => window.location.assign('/auth/google')} /></div>
123+
: null
124124
}
125125
<div
126126
id="users"
Binary file not shown.

client/src/components/header/styles/header.scss

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@
55
display: flex;
66
justify-content: center;
77
align-items: center;
8-
#authbutton{
9-
margin-top: 25px;
10-
width: auto;
11-
height: 100%;
12-
#login{
13-
width: 232px;
14-
height: 70%;
15-
background: url('btn_google_signin_dark_normal_web@2x.png');
16-
background-size: 100% 100%;
17-
background-repeat: no-repeat;
18-
cursor: pointer;
19-
outline: none;
20-
}
21-
}
22-
238
#users{
249
position: absolute;
2510
right: 0;

client/src/components/oponnent/opponent.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import './styles/opponentdescription.scss';
1111
import soundFile from './styles/WPN.wav';
1212

1313
// read from store
14-
const mapStateToProps = ({ game, socket: { temp } }) => ({ game, temp });
14+
const mapStateToProps = ({
15+
game,
16+
socket: { temp },
17+
user
18+
}) =>
19+
({ game, temp, user });
1520
const {
1621
clientEmit: {
1722
LOOK_FOR_OPPONENTS,
@@ -163,12 +168,12 @@ export class Opponent extends React.Component {
163168
const { levelsRaised } = this.state;
164169
const {
165170
temp:
166-
{
167-
gameInProgress:
168-
{
169-
info: { difficulty },
170-
},
171-
},
171+
{
172+
gameInProgress:
173+
{
174+
info: { difficulty },
175+
},
176+
},
172177
onFloorRaise, floorsRaisedOnOpp,
173178
} = this.props;
174179
const {
@@ -233,8 +238,7 @@ export class Opponent extends React.Component {
233238
);
234239

235240
render() {
236-
const { difficulty, game, temp } = this.props;
237-
if (!temp) return null;
241+
const { difficulty, game, temp, user } = this.props;
238242
return (
239243
<div className="opponentContainer">
240244
<OpponentDescription
@@ -243,6 +247,7 @@ export class Opponent extends React.Component {
243247
setDifficulty={this.setDifficulty}
244248
requestInvite={sId => this.requestInvite(sId)}
245249
getPool={() => this.resetMultiplayer()}
250+
authenticated={user && user.profile && user.profile.authenticated}
246251
/>
247252
<canvas
248253
ref={this.canvasOpponent}

client/src/components/oponnent/opponentInfo.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import PropTypes from 'prop-types';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import {
66
Box, ButtonGroup, Button, CircularProgress,
7-
} from '@material-ui/core';
7+
} from '@mui/material';
88
import {
99
faSyncAlt,
1010
} from '@fortawesome/free-solid-svg-icons';
11+
import GoogleIcon from '@mui/icons-material/Google';
1112
import './styles/opponentdescription.scss';
1213

1314
/* opponent top part of component */
@@ -17,12 +18,24 @@ const OpponentDescription = ({
1718
setDifficulty,
1819
requestInvite,
1920
getPool,
21+
authenticated
2022
}) => {
23+
if (!temp) return null
2124
const {
2225
opponents, invitationTo, declinedInvitation,
2326
acceptedInvitation, gameInProgress, gameOver,
2427
} = temp;
2528
// stage 1 - no logged in opponents in multiplayer mode found
29+
if (!authenticated) {
30+
return (
31+
<Button id="googleloginbutton"
32+
variant="outlined" startIcon={<GoogleIcon style={{ fontSize: 25 }} />}
33+
onClick={() => window.location.assign('/auth/google')}>
34+
Continue With Google
35+
</Button>
36+
);
37+
}
38+
2639
if (opponents && !opponents.length) {
2740
return (
2841
<div className="opponentContainer__opponentDescription">
@@ -66,7 +79,7 @@ const OpponentDescription = ({
6679
key={d}
6780
role="button"
6881
onClick={() => setDifficulty(d)}
69-
onKeyDown={() => {}}
82+
onKeyDown={() => { }}
7083
tabIndex={0}
7184
style={{
7285
maxWidth: 35, maxHeight: 35, minWidth: 35, minHeight: 35,
@@ -176,5 +189,6 @@ OpponentDescription.propTypes = {
176189
requestInvite: PropTypes.func,
177190
difficulty: PropTypes.number,
178191
getPool: PropTypes.func,
192+
authenticated: PropTypes.bool,
179193
};
180194
export default OpponentDescription;

client/src/components/oponnent/styles/opponentdescription.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
#googleloginbutton{
2+
border: 0px;
3+
height: 40px;
4+
display: flex;
5+
justify-content: space-around;
6+
align-items: center;
7+
border-radius: 2px;
8+
padding: 1px;
9+
font-size: 15px;
10+
font-weight: bold;
11+
outline: none;
12+
box-shadow: none;
13+
cursor: pointer;
14+
background-clip: padding-box;
15+
transition: opacity .2s linear;
16+
width: 268px;
17+
margin-top: 10px;
18+
color:white;
19+
background-color: #4285F4;
20+
.buttontext{
21+
padding-right: 45px;
22+
}
23+
}
24+
125
.opponentContainer{
226
margin-left: 30px;
327
margin-right:30px;

client/tests/src/components/game/__snapshots__/game.test.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ exports[`The Game component will display the game for allowed screen sizes 1`] =
125125
tabIndex="0"
126126
width={300}
127127
/>
128+
<Connect(Opponent)
129+
difficulty={2}
130+
floorsRaisedOnOpp={[Function]}
131+
onCanvasFocus={[Function]}
132+
onFloorRaise={[Function]}
133+
onGameOver={[Function]}
134+
onReset={[Function]}
135+
onSetDifficulty={[Function]}
136+
toggleMultiplayer={[Function]}
137+
/>
128138
<Audio
129139
clearAudio={
130140
Object {

client/tests/src/components/header/__snapshots__/header.test.js.snap

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ exports[`The header will render for unauthenticated users 1`] = `
4444
<div
4545
id="header"
4646
>
47-
<div
48-
id="authbutton"
49-
>
50-
<button
51-
id="login"
52-
onClick={[Function]}
53-
type="submit"
54-
/>
55-
</div>
5647
<div
5748
id="users"
5849
onClick={[Function]}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`will render the invitation modal 1`] = `
4-
<WithStyles(ForwardRef(Dialog))
4+
<ForwardRef(Dialog)
55
aria-labelledby="simple-dialog-title"
66
open={true}
77
>
8-
<WithStyles(ForwardRef(DialogTitle))
8+
<ForwardRef(DialogTitle)
99
id="simple-dialog-title"
1010
>
1111
stub_Invite_name invites you to a duel!
12-
</WithStyles(ForwardRef(DialogTitle))>
13-
<WithStyles(ForwardRef(DialogContent))>
14-
<WithStyles(ForwardRef(Chip))
12+
</ForwardRef(DialogTitle)>
13+
<ForwardRef(DialogContent)>
14+
<ForwardRef(Chip)
1515
avatar={
16-
<WithStyles(ForwardRef(Avatar))>
16+
<ForwardRef(Avatar)>
1717
3
18-
</WithStyles(ForwardRef(Avatar))>
18+
</ForwardRef(Avatar)>
1919
}
2020
color="primary"
2121
label="Difficulty"
@@ -26,13 +26,13 @@ exports[`will render the invitation modal 1`] = `
2626
}
2727
}
2828
/>
29-
</WithStyles(ForwardRef(DialogContent))>
30-
<WithStyles(ForwardRef(DialogActions))>
31-
<WithStyles(ForwardRef(ButtonGroup))
29+
</ForwardRef(DialogContent)>
30+
<ForwardRef(DialogActions)>
31+
<ForwardRef(ButtonGroup)
3232
aria-label="vertical outlined primary button group"
3333
color="primary"
3434
>
35-
<WithStyles(ForwardRef(Button))
35+
<ForwardRef(Button)
3636
onClick={[Function]}
3737
size="large"
3838
style={
@@ -45,8 +45,8 @@ exports[`will render the invitation modal 1`] = `
4545
variant="contained"
4646
>
4747
Accept
48-
</WithStyles(ForwardRef(Button))>
49-
<WithStyles(ForwardRef(Button))
48+
</ForwardRef(Button)>
49+
<ForwardRef(Button)
5050
onClick={[Function]}
5151
size="large"
5252
style={
@@ -59,8 +59,8 @@ exports[`will render the invitation modal 1`] = `
5959
variant="contained"
6060
>
6161
Decline
62-
</WithStyles(ForwardRef(Button))>
63-
</WithStyles(ForwardRef(ButtonGroup))>
64-
</WithStyles(ForwardRef(DialogActions))>
65-
</WithStyles(ForwardRef(Dialog))>
62+
</ForwardRef(Button)>
63+
</ForwardRef(ButtonGroup)>
64+
</ForwardRef(DialogActions)>
65+
</ForwardRef(Dialog)>
6666
`;

0 commit comments

Comments
 (0)