diff --git a/src/containers/ConnectPage.js b/src/containers/ConnectPage.js
index 3898dc0..7a26fed 100644
--- a/src/containers/ConnectPage.js
+++ b/src/containers/ConnectPage.js
@@ -33,7 +33,8 @@ class ConnectPage extends React.Component {
const { actions, login, router, socket } = props;
if (socket.state === STATE_OPEN)
{
- switch (login.status) {
+ const loginStatus = login.get("status");
+ switch (loginStatus) {
case LOGIN_STATUS_UNKNOWN:
actions.login.getStatus();
break;
@@ -46,22 +47,10 @@ class ConnectPage extends React.Component {
}
render() {
- const { actions, login, socket } = this.props;
-
- let loginStatusPane;
-
- if (socket.state === STATE_OPEN &&
- login.status === LOGIN_STATUS_UNKNOWN)
- {
- loginStatusPane = (
-
- );
- }
-
+ const { actions, socket } = this.props;
return (
- {loginStatusPane}
);
}
diff --git a/src/containers/Footer.js b/src/containers/Footer.js
index bfbeaaf..99d8e8c 100644
--- a/src/containers/Footer.js
+++ b/src/containers/Footer.js
@@ -1,5 +1,6 @@
import React, { PropTypes } from "react";
import { connect } from "react-redux";
+import ImmutablePropTypes from "react-immutable-proptypes";
import LoginStatusPane from "../components/LoginStatusPane";
import SocketStatusPane from "../components/SocketStatusPane";
@@ -8,13 +9,18 @@ const Footer = ({ login, socket }) => {
return (
);
};
Footer.propTypes = {
- login: PropTypes.object.isRequired,
+ login: ImmutablePropTypes.map.isRequired,
socket: PropTypes.object.isRequired
};
diff --git a/src/containers/RoomsPane.js b/src/containers/RoomsPane.js
index c293d8f..a27dcdc 100644
--- a/src/containers/RoomsPane.js
+++ b/src/containers/RoomsPane.js
@@ -67,8 +67,8 @@ RoomsPane.propTypes = {
};
const mapStateToProps = (state) => ({
- roomMap: state.rooms.get("roomMap"),
- loginUserName: state.login.username
+ roomMap: state.rooms.get("roomMap"),
+ loginUserName: state.login.get("username")
});
const mapDispatchToProps = (dispatch) => ({
diff --git a/src/createRoutes.js b/src/createRoutes.js
index 17e6a47..c82e29f 100644
--- a/src/createRoutes.js
+++ b/src/createRoutes.js
@@ -13,7 +13,7 @@ const createRoutes = (store) => {
const requireLoggedIn = (nextState, replaceState) => {
let { socket, login } = store.getState();
if (socket.state !== STATE_OPEN ||
- login.status !== LOGIN_STATUS_SUCCESS)
+ login.get("status") !== LOGIN_STATUS_SUCCESS)
{
replaceState({}, "/");
}
diff --git a/src/reducers/login.js b/src/reducers/login.js
index 04969c2..59f6c8e 100644
--- a/src/reducers/login.js
+++ b/src/reducers/login.js
@@ -1,3 +1,5 @@
+import Immutable from "immutable";
+
import {
LOGIN_GET_STATUS,
SOCKET_RECEIVE_MESSAGE
@@ -11,9 +13,9 @@ import {
LOGIN_STATUS_FAILURE
} from "../constants/login";
-const initialState = {
+const initialState = Immutable.Map({
status: LOGIN_STATUS_UNKNOWN
-};
+});
const reduceReceiveMessage = (state, message) => {
const { variant, data } = message;
@@ -26,29 +28,26 @@ const reduceReceiveMessage = (state, message) => {
case "Pending":
{ // sub-block required otherwise const username declarations clash
const [ username ] = data.fields;
- return {
- status: LOGIN_STATUS_PENDING,
- username
- };
+ return state
+ .set("status", LOGIN_STATUS_PENDING)
+ .set("username", username);
}
case "Success":
{ // sub-block required otherwise const username declarations clash
const [ username, motd ] = data.fields;
- return {
- status: LOGIN_STATUS_SUCCESS,
- username,
- motd
- };
+ return state
+ .set("status", LOGIN_STATUS_SUCCESS)
+ .set("username", username)
+ .set("motd", motd);
}
case "Failure":
{ // sub-block required otherwise const username declarations clash
const [ username, reason ] = data.fields;
- return {
- status: LOGIN_STATUS_FAILURE,
- username,
- reason
- };
+ return state
+ .set("status", LOGIN_STATUS_FAILURE)
+ .set("username", username)
+ .set("reason", reason);
}
default:
@@ -60,10 +59,7 @@ export default (state = initialState, action) => {
const { type, payload } = action;
switch (type) {
case LOGIN_GET_STATUS:
- return {
- ...state,
- status: LOGIN_STATUS_GETTING
- };
+ return state.set("status", LOGIN_STATUS_GETTING);
case SOCKET_RECEIVE_MESSAGE:
return reduceReceiveMessage(state, payload);