Skip to content

Commit 82fe023

Browse files
committed
more cleanup
1 parent 43478f7 commit 82fe023

File tree

6 files changed

+26
-40
lines changed

6 files changed

+26
-40
lines changed

client/src/components/header/header.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export class Header extends React.Component {
7070
const { getUser: getUserStatus } = this.props;
7171
await getUserStatus();
7272
const { user } = this.props;
73-
user.profile.remove = true;
74-
clientEmitter(USER_LOGGED_OUT, user.profile);
73+
clientEmitter(USER_LOGGED_OUT,{ ...user.profile, remove: true});
7574
window.location.assign('/auth/logout');
7675
};
7776

client/src/components/oponnent/opponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ export class Opponent extends React.Component {
251251
multiPlayer={multiPlayer}
252252
usersLoggedIn={usersLoggedIn}
253253
/>
254-
<canvas
254+
{multiPlayer && <canvas
255255
ref={this.canvasOpponent}
256256
width={game.canvas.canvasMajor.width / 2}
257257
height={game.canvas.canvasMajor.height / 2}
258-
/>
258+
/>}
259259
{this.audioPlayer()}
260260
</div>
261261
);

client/src/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
/* default CRA imports */
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4+
import { BrowserRouter, Route, Switch } from 'react-router-dom';
45
import './index.css';
5-
/* custom imports */
66
import { Provider } from 'react-redux';
7-
import {store} from './store';
8-
import Router from './routes/index';
7+
import { store } from './store';
8+
import Header from './components/header/header';
9+
import Profile from './components/profile/profile';
10+
import Footer from './components/footer/footer';
11+
import Game from './components/game/game'
912

1013

1114
ReactDOM.render(
1215
<Provider store={store}>
13-
<Router />
16+
<BrowserRouter>
17+
<React.Fragment>
18+
<Header />
19+
<Switch>
20+
<Route path="/" exact component={Game} />
21+
<Route path="/profile" component={Profile} />
22+
</Switch>
23+
<Footer />
24+
</React.Fragment>
25+
</BrowserRouter>
1426
</Provider>,
1527
document.getElementById('root'),
1628
);

client/src/routes/index.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

client/src/sockethandler.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { socket as socketConstants } from './constants/index';
44

55
const {
66
serverEmit: {
7-
SERVER_RESET, ACCEPTED_INVITATION, GAME_STARTED, OPPONENT_SCREEN,
7+
ACCEPTED_INVITATION, GAME_STARTED, OPPONENT_SCREEN,
88
},
99
clientEmit: { SEND_LOGGED_IN_USER },
1010
GAME_COUNTDOWN,
@@ -13,7 +13,7 @@ const {
1313

1414
const { dispatch } = store;
1515

16-
export const socketConnection = io(CONNECTION);
16+
const socketConnection = io(CONNECTION);
1717

1818
export const clientEmitter = (event, dataToEmit) => {
1919
socketConnection.emit(event, dataToEmit);
@@ -65,6 +65,7 @@ OPPONENT_SCREEN: triggered by: UPDATED_CLIENT_SCREEN
6565
FINISH_GAME: triggered by: GAME_OVER
6666
*/
6767

68+
// used for client side manipulation of incoming special events before dispatching
6869
const socketActionMap = {
6970
SERVER_RESET: () => serverReset(),
7071
ACCEPTED_INVITATION: (data) => {
@@ -83,17 +84,16 @@ const socketActionMap = {
8384

8485
export const handleServerSocketResponses = (event, ...args) => {
8586
if (!Object.keys(socketConstants.serverEmit).includes(event)) {
86-
console.log(`No action map found for event = ${event}`);
87+
console.log(`No dispatch handler found for incoming event = ${event}`);
8788
return;
8889
}
8990
const [data, callback] = args;
90-
const specialEvents = [SERVER_RESET, ACCEPTED_INVITATION, GAME_STARTED, OPPONENT_SCREEN]
9191

92-
if (specialEvents.includes(event)) {
92+
if (Object.keys(socketActionMap).includes(event)) {
9393
return socketActionMap[event](data, callback);
94-
} else {
95-
dispatch({ type: `socket/${event}`, payload: data });
9694
}
95+
96+
return dispatch({ type: `socket/${event}`, payload: data });
9797
}
9898

9999
socketConnection.onAny((event, ...args) => handleServerSocketResponses(event, ...args));

client/tests/src/components/oponnent/__snapshots__/opponent.test.js.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ exports[`The Opponent component will render the oponent window 1`] = `
1111
setDifficulty={[Function]}
1212
socketState={Object {}}
1313
/>
14-
<canvas
15-
height={300}
16-
width={150}
17-
/>
1814
<audio
1915
src={
2016
Object {

0 commit comments

Comments
 (0)