Skip to content

Commit 71a3fe1

Browse files
fix(deployment): fix server deployment bugs (#85)
* fix(deployment): fix server deployment bugs * fix(leaderboard): remove student dropdown
1 parent b1ef3b4 commit 71a3fe1

File tree

10 files changed

+220
-196
lines changed

10 files changed

+220
-196
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ COPY src/config/config.example.ts src/config/config.ts
99

1010
COPY . .
1111

12-
RUN npm run build
12+
RUN mkdir -p build && npm run build
1313

1414
WORKDIR /usr/src/app/server
1515

__tests__/app/containers/SideBar.test.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SidePanelTab } from 'app/reducers/Dashboard';
55
import { configureStore } from 'app/store';
66
import { mount } from 'enzyme';
77
import * as React from 'react';
8+
import { BrowserRouter } from 'react-router-dom';
89

910
describe('SideBar Container', () => {
1011
const { store } = configureStore();
@@ -17,6 +18,7 @@ describe('SideBar Container', () => {
1718
context: {
1819
store,
1920
},
21+
wrappingComponent: BrowserRouter,
2022
},
2123
);
2224

__tests__/app/containers/__snapshots__/SideBar.test.tsx.snap

+170-117
Large diffs are not rendered by default.

server/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ app.get('/*', (req, res) => {
99
});
1010

1111
app.listen(5000);
12-
console.log('Server is listening on http://localhost:5000');
12+
console.log('Server is listening on http://localhost:5000');

src/app/components/Dashboard.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import GameLog from 'app/containers/GameLog';
66
import Renderer from 'app/containers/Renderer';
77
import SideBar from 'app/containers/SideBar';
88
import SidePanel from 'app/containers/SidePanel';
9-
import SocketHandler from 'app/containers/SocketHandler';
109
import SubmitBar from 'app/containers/SubmitBar';
1110
import { Routes } from 'app/routes';
1211
import * as style from 'app/styles/Dashboard.css';
@@ -118,7 +117,6 @@ export class Dashboard extends React.Component<
118117
{isLoggedIn && isReactTourActive && !isWelcomeModalOpen ? (
119118
<ReactTour toggleReactTour={this.onToggleReactTour} />
120119
) : null}
121-
{isLoggedIn ? <SocketHandler /> : null}
122120
<SplitPane
123121
style={{
124122
filter: `blur(${isAuthenticationOpen || isWelcomeModalOpen ? 2 : 0}px)`,

src/app/components/Leaderboard/index.tsx

-55
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1313
import { NavBar, NavPage } from 'app/components/home/Navbar';
1414
import { LeaderboardElement } from 'app/components/Leaderboard/LeaderboardElement';
1515
import { Timer } from 'app/components/Leaderboard/Timer';
16-
import SocketHandler from 'app/containers/SocketHandler';
1716
import { Routes } from 'app/routes';
1817
import * as styles from 'app/styles/Leaderboard.module.css';
1918
import * as LeaderboardInterfaces from 'app/types/Leaderboard';
@@ -94,7 +93,6 @@ export class Leaderboard extends React.Component<
9493
<>
9594
<NavBar isLoggedIn={isLoggedIn} page={NavPage.LEADERBOARD} />
9695
<Grid fluid={true} className={classnames(styles.Leaderboard)}>
97-
{isLoggedIn ? <SocketHandler /> : null}
9896
<Row className={classnames('py-4 pl-3')}>
9997
<Col
10098
sm={9}
@@ -185,59 +183,6 @@ export class Leaderboard extends React.Component<
185183
</div>
186184
</div>
187185
</Col>
188-
<Col>
189-
<div className={styles.dropdown}>
190-
<button className={styles.dropbtn}>
191-
{LeaderboardInterfaces.UserTypeName[this.state.currentUserType]}
192-
</button>
193-
<FontAwesomeIcon style={{ color: 'white' }} icon={faCaretDown} />
194-
<div className={styles['dropdown-content']}>
195-
<a
196-
style={{ cursor: 'pointer' }}
197-
onClick={() => {
198-
this.setState({
199-
currentUserType: LeaderboardInterfaces.UserType.STUDENT,
200-
});
201-
}}
202-
className={
203-
this.state.currentUserType === LeaderboardInterfaces.UserType.STUDENT
204-
? classnames(styles.dropDownMenuActive, styles.dropDownMenuActive)
205-
: classnames(styles.dropDownMenu)
206-
}
207-
>
208-
{LeaderboardInterfaces.UserTypeName.STUDENT}
209-
</a>
210-
<a
211-
style={{ cursor: 'pointer' }}
212-
onClick={() => {
213-
this.setState({
214-
currentUserType: LeaderboardInterfaces.UserType.PROFESSIONAL,
215-
});
216-
}}
217-
className={
218-
this.state.currentUserType === LeaderboardInterfaces.UserType.PROFESSIONAL
219-
? classnames(styles.dropDownMenuActive, styles.dropDownMenuActive)
220-
: classnames(styles.dropDownMenu)
221-
}
222-
>
223-
{LeaderboardInterfaces.UserTypeName.PROFESSIONAL}
224-
</a>
225-
<a
226-
style={{ cursor: 'pointer' }}
227-
onClick={() => {
228-
this.setState({ currentUserType: LeaderboardInterfaces.UserType.ALL });
229-
}}
230-
className={
231-
this.state.currentUserType === LeaderboardInterfaces.UserType.ALL
232-
? classnames(styles.dropDownMenuActive, styles.dropDownMenuActive)
233-
: classnames(styles.dropDownMenu)
234-
}
235-
>
236-
{LeaderboardInterfaces.UserTypeName.All}
237-
</a>
238-
</div>
239-
</div>
240-
</Col>
241186
<Col style={{ position: 'absolute', left: '96.5%' }}>
242187
<button
243188
className={styles.button}

src/app/components/SideBar.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as React from 'react';
2323
import { Button, ButtonGroup } from 'react-bootstrap';
2424

2525
import Tooltip from '@material-ui/core/Tooltip';
26+
import { Link } from 'react-router-dom';
2627

2728
export class Sidebar extends React.Component<SideBarInterfaces.Props, {}> {
2829
public render() {
@@ -84,16 +85,16 @@ export class Sidebar extends React.Component<SideBarInterfaces.Props, {}> {
8485
</Button>
8586
</Tooltip>
8687
<Tooltip title="Leaderboard" placement="right">
87-
<a
88-
href="./leaderboard"
88+
<Link
89+
to="/leaderboard"
8990
className={classnames('py-2 px-auto leaderboard-btn-ctrl', styles.customBtn, {
9091
[`${styles.customBtnActive}`]: sidePanelTab === SidePanelTab.LEADERBOARD,
9192
})}
9293
id="leaderboard_button"
9394
onClick={() => clearAllLogs()}
9495
>
9596
<FontAwesomeIcon icon={faTrophy} />
96-
</a>
97+
</Link>
9798
</Tooltip>
9899
{isLoggedIn ? (
99100
<Tooltip title="Commit Log" placement="right">
@@ -145,8 +146,8 @@ export class Sidebar extends React.Component<SideBarInterfaces.Props, {}> {
145146
</Button>
146147
</Tooltip>
147148
<Tooltip title={isLoggedIn ? 'Profile' : 'Login'} placement="right">
148-
<Button
149-
href={'./profile'}
149+
<Link
150+
to="/profile"
150151
className={classnames('py-2 px-auto', styles.customBtn)}
151152
id="user_profile_button"
152153
onClick={() => {
@@ -158,7 +159,7 @@ export class Sidebar extends React.Component<SideBarInterfaces.Props, {}> {
158159
}}
159160
>
160161
<FontAwesomeIcon icon={isLoggedIn ? faUser : faSignInAlt} />
161-
</Button>
162+
</Link>
162163
</Tooltip>
163164
{isLoggedIn ? (
164165
<Tooltip title="Logout" placement="right">
@@ -175,17 +176,17 @@ export class Sidebar extends React.Component<SideBarInterfaces.Props, {}> {
175176
</Tooltip>
176177
) : null}
177178
<Tooltip title="Home" placement="right">
178-
<a
179+
<Link
179180
className={classnames(
180181
'py-2 px-auto notification-btn-ctrl',
181182
styles.customBtn,
182183
styles.infoCircle,
183184
)}
184-
href="./home"
185+
to="/home"
185186
onClick={() => clearAllLogs()}
186187
>
187188
<FontAwesomeIcon icon={faInfoCircle} />
188-
</a>
189+
</Link>
189190
</Tooltip>
190191
<Tooltip title="Take a tour" placement="right">
191192
<Button
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import SocketHandler from 'app/containers/SocketHandler';
2+
import * as React from 'react';
3+
4+
export class SocketHandlerWrapper extends React.Component<{ isLoggedIn: boolean }> {
5+
public render() {
6+
return this.props.isLoggedIn ? <SocketHandler /> : null;
7+
}
8+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SocketHandlerWrapper } from 'app/components/SocketHandlerWrapper';
2+
import { RootState } from 'app/reducers';
3+
import { connect } from 'react-redux';
4+
5+
const mapStateToProps = (rootState: RootState) => {
6+
return {
7+
isLoggedIn: rootState.user.isLoggedIn,
8+
};
9+
};
10+
11+
const socketHandlerWrapperContainer = connect(mapStateToProps)(SocketHandlerWrapper);
12+
13+
export default socketHandlerWrapperContainer;

src/app/index.tsx

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Register from 'app/containers/Authentication/Register';
44
import Dashboard from 'app/containers/Dashboard';
55
import LandingPage from 'app/containers/LandingPage';
66
import Leaderboard from 'app/containers/Leaderboard';
7+
import SocketHandlerWrapper from 'app/containers/SocketHandlerWrapper';
78
import UserProfileModal from 'app/containers/UserProfileModal';
89
import { Routes } from 'app/routes';
910
// @ts-ignore
@@ -17,15 +18,18 @@ initializeRendererAssets();
1718

1819
/* tslint:disable-next-line:variable-name */
1920
export const App = hot(module)(() => (
20-
<BrowserRouter>
21-
<Switch>
22-
<Route exact path={Routes.ROOT} component={Dashboard} />
23-
<Route exact path={Routes.LOGIN} component={Login} />
24-
<Route exact path={Routes.REGISTER} component={Register} />
25-
<Route exact path={Routes.LEADERBOARD} component={Leaderboard} />
26-
<Route exact path={Routes.USER_PROFILE_MODEL} component={UserProfileModal} />
27-
<Route path={Routes.USER_ACTIVATION} component={ActivateUser} />
28-
<Route exact path={Routes.HOME} component={LandingPage} />
29-
</Switch>
30-
</BrowserRouter>
21+
<React.Fragment>
22+
<SocketHandlerWrapper />
23+
<BrowserRouter>
24+
<Switch>
25+
<Route exact path={Routes.ROOT} component={Dashboard} />
26+
<Route exact path={Routes.LOGIN} component={Login} />
27+
<Route exact path={Routes.REGISTER} component={Register} />
28+
<Route exact path={Routes.LEADERBOARD} component={Leaderboard} />
29+
<Route exact path={Routes.USER_PROFILE_MODEL} component={UserProfileModal} />
30+
<Route path={Routes.USER_ACTIVATION} component={ActivateUser} />
31+
<Route exact path={Routes.HOME} component={LandingPage} />
32+
</Switch>
33+
</BrowserRouter>
34+
</React.Fragment>
3135
));

0 commit comments

Comments
 (0)