Browse Source

Start migrating away from SOCKET_SEND_MESSAGE action.

pull/1/head
Titouan Rigoudy 9 years ago
parent
commit
bdad6d168f
6 changed files with 28 additions and 15 deletions
  1. +3
    -3
      src/actions/LoginActions.js
  2. +5
    -4
      src/components/LoginStatusPane.js
  3. +1
    -1
      src/components/SolsticeApp.js
  4. +2
    -0
      src/containers/App.js
  5. +1
    -1
      src/containers/Footer.js
  6. +16
    -6
      src/reducers/socket.js

+ 3
- 3
src/actions/LoginActions.js View File

@ -1,7 +1,7 @@
import { LOGIN_GET_STATUS } from "../actions/ActionTypes";
import { LOGIN_GET_STATUS } from "../constants/ActionTypes";
export default { export default {
requestStatus: () => ({
type: LOGIN_GET_STATUS,
getStatus: () => ({
type: LOGIN_GET_STATUS
}) })
}; };

+ 5
- 4
src/components/LoginStatusPane.js View File

@ -1,7 +1,6 @@
import React, { PropTypes } from "react"; import React, { PropTypes } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import ControlRequest from "../utils/ControlRequest";
import propTypeSymbol from "../utils/propTypeSymbol"; import propTypeSymbol from "../utils/propTypeSymbol";
import { import {
LOGIN_STATUS_UNKNOWN, LOGIN_STATUS_UNKNOWN,
@ -20,9 +19,9 @@ class LoginStatusPane extends React.Component
} }
componentDidMount() { componentDidMount() {
const { status, socketSend } = this.props;
const { status, loginActions } = this.props;
if (status == LOGIN_STATUS_UNKNOWN) { if (status == LOGIN_STATUS_UNKNOWN) {
this.props.socketSend(ControlRequest.loginStatus());
loginActions.getStatus();
} }
} }
@ -99,7 +98,9 @@ LoginStatusPane.propTypes = {
username: PropTypes.string, username: PropTypes.string,
motd: PropTypes.string, motd: PropTypes.string,
reason: PropTypes.string, reason: PropTypes.string,
socketSend: PropTypes.func.isRequired
loginActions: PropTypes.shape({
getStatus: PropTypes.func.isRequired
}).isRequired
}; };
export default LoginStatusPane; export default LoginStatusPane;

+ 1
- 1
src/components/SolsticeApp.js View File

@ -26,7 +26,7 @@ const SolsticeApp = (props) => {
return ( return (
<div id={ID}> <div id={ID}>
<ConnectForm socket={socket} actions={actions} /> <ConnectForm socket={socket} actions={actions} />
<LoginStatusPane {...login} socketSend={actions.socket.send} />
<LoginStatusPane {...login} loginActions={actions.login} />
</div> </div>
); );
} }


+ 2
- 0
src/containers/App.js View File

@ -4,6 +4,7 @@ import React, {PropTypes} from "react";
import { bindActionCreators } from "redux"; import { bindActionCreators } from "redux";
import { connect } from "react-redux"; import { connect } from "react-redux";
import LoginActions from "../actions/LoginActions";
import RoomActions from "../actions/RoomActions"; import RoomActions from "../actions/RoomActions";
import SocketActions from "../actions/SocketActions"; import SocketActions from "../actions/SocketActions";
import SocketHandlerActions from "../actions/SocketHandlerActions"; import SocketHandlerActions from "../actions/SocketHandlerActions";
@ -23,6 +24,7 @@ const mapStateToProps = ({ socket, login }) => ({ socket, login });
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return { return {
actions: { actions: {
login: bindActionCreators(LoginActions, dispatch),
room: bindActionCreators(RoomActions, dispatch), room: bindActionCreators(RoomActions, dispatch),
socket: bindActionCreators(SocketActions, dispatch), socket: bindActionCreators(SocketActions, dispatch),
socketHandlers: bindActionCreators(SocketHandlerActions, dispatch) socketHandlers: bindActionCreators(SocketHandlerActions, dispatch)


+ 1
- 1
src/containers/Footer.js View File

@ -8,7 +8,7 @@ const Footer = ({ actions, login, socket }) => {
return ( return (
<footer> <footer>
<SocketStatusPane {...socket} /> <SocketStatusPane {...socket} />
<LoginStatusPane {...login} socketSend={actions.socket.send} />
<LoginStatusPane {...login} loginActions={actions.login} />
</footer> </footer>
); );
}; };


+ 16
- 6
src/reducers/socket.js View File

@ -1,13 +1,23 @@
import * as types from "../constants/ActionTypes"; import * as types from "../constants/ActionTypes";
import { import {
STATE_OPENING, STATE_OPEN, STATE_CLOSING, STATE_CLOSED STATE_OPENING, STATE_OPEN, STATE_CLOSING, STATE_CLOSED
} from "../constants/socket.js";
} from "../constants/socket";
import ControlRequest from "../utils/ControlRequest";
const initialState = { const initialState = {
state: STATE_CLOSED state: STATE_CLOSED
}; };
export default (state = initialState, action) => { export default (state = initialState, action) => {
const sendRequest = (controlRequest) => {
try {
state.socket.send(JSON.stringify(controlRequest));
} catch (err) {
console.log(`Socket error: failed to send ${action.payload}`);
}
};
switch (action.type) { switch (action.type) {
case types.SOCKET_SET_OPENING: case types.SOCKET_SET_OPENING:
{ {
@ -44,11 +54,11 @@ export default (state = initialState, action) => {
return { ...state, state: state.socket.readyState }; return { ...state, state: state.socket.readyState };
case types.SOCKET_SEND_MESSAGE: case types.SOCKET_SEND_MESSAGE:
try {
state.socket.send(JSON.stringify(action.payload));
} catch (err) {
console.log(`Socket error: failed to send ${action.payload}`);
}
sendRequest(action.payload);
return state;
case types.LOGIN_GET_STATUS:
sendRequest(ControlRequest.loginStatus());
return state; return state;
default: default:


Loading…
Cancel
Save