From 79226dc5946afe85157ac14b81f04d0ebd7c881f Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Tue, 12 Apr 2016 15:05:10 +0200 Subject: [PATCH] Display messages in a modern way. --- src/components/RoomChatMessageList.js | 35 ++++++++++++------- src/components/SolsticeApp.js | 2 +- src/containers/RoomChat.js | 19 ++++++++--- src/containers/RoomsPane.js | 19 +++++++---- src/styles/styles.scss | 48 +++++++++++++++++++++++++-- 5 files changed, 97 insertions(+), 26 deletions(-) diff --git a/src/components/RoomChatMessageList.js b/src/components/RoomChatMessageList.js index 883c9ef..3c1d3b5 100644 --- a/src/components/RoomChatMessageList.js +++ b/src/components/RoomChatMessageList.js @@ -1,28 +1,39 @@ import React, { PropTypes } from "react"; import ImmutablePropTypes from "react-immutable-proptypes"; -const RoomChatMessageList = ({ messages }) => { +const RoomChatMessageList = ({ login_user_name, messages }) => { // Append all messages in the chat room. const children = []; let i = 0; for (const { user_name, message } of messages) { - children.push( -
  • - {user_name}: {message} -
  • - ); + if (user_name == login_user_name) { + children.push( +
  • +
    {message}
    +
  • + ); + } else { + children.push( +
  • +
    {user_name}
    +
    {message}
    +
  • + ); + } i++; } - return ( -
    - -
    - ); + return ; }; RoomChatMessageList.propTypes = { - messages: ImmutablePropTypes.list.isRequired + login_user_name: PropTypes.string.isRequired, + messages: ImmutablePropTypes.listOf( + PropTypes.shape({ + user_name: PropTypes.string.isRequired, + message: PropTypes.string.isRequired + }).isRequired + ).isRequired }; export default RoomChatMessageList; diff --git a/src/components/SolsticeApp.js b/src/components/SolsticeApp.js index 05b484c..725b7bf 100644 --- a/src/components/SolsticeApp.js +++ b/src/components/SolsticeApp.js @@ -23,7 +23,7 @@ const SolsticeApp = (props) => {
    - +
    diff --git a/src/containers/RoomChat.js b/src/containers/RoomChat.js index 2662a5e..a9141f0 100644 --- a/src/containers/RoomChat.js +++ b/src/containers/RoomChat.js @@ -1,4 +1,5 @@ import React, { PropTypes } from "react"; +import ImmutablePropTypes from "react-immutable-proptypes"; import RoomChatForm from "../components/RoomChatForm"; import RoomChatMessageList from "../components/RoomChatMessageList"; @@ -37,7 +38,7 @@ class RoomChat extends React.Component { } render() { - const { name, room, roomActions } = this.props; + const { login_user_name, name, room, roomActions } = this.props; // If no room is selected, just tell the user to select one. if (!name || !room) { @@ -59,7 +60,10 @@ class RoomChat extends React.Component { return (
    {name}
    - +
    ); @@ -67,9 +71,16 @@ class RoomChat extends React.Component { } RoomChat.propTypes = { - room: PropTypes.object, + login_user_name: PropTypes.string.isRequired, name: PropTypes.string, - roomActions: PropTypes.object.isRequired + room: PropTypes.shape({ + membership: PropTypes.string.isRequired, + messages: ImmutablePropTypes.list.isRequired + }), + roomActions: PropTypes.shape({ + join: PropTypes.func.isRequired, + say: PropTypes.func.isRequired + }).isRequired }; export default RoomChat; diff --git a/src/containers/RoomsPane.js b/src/containers/RoomsPane.js index a4b0ed3..eff6ce8 100644 --- a/src/containers/RoomsPane.js +++ b/src/containers/RoomsPane.js @@ -1,6 +1,7 @@ import React, { PropTypes } from "react"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; +import ImmutablePropTypes from "react-immutable-proptypes"; import RoomList from "../components/RoomList"; @@ -14,18 +15,19 @@ class RoomsPane extends React.Component { } render() { - const { actions, rooms, selected } = this.props; + const { login_user_name, rooms, roomActions, selected } = this.props; return (
    ); @@ -33,12 +35,17 @@ class RoomsPane extends React.Component { } RoomsPane.propTypes = { - actions: PropTypes.object.isRequired, - rooms: PropTypes.object.isRequired, + login_user_name: PropTypes.string.isRequired, + rooms: ImmutablePropTypes.orderedMap.isRequired, + roomActions: PropTypes.object.isRequired, selected: PropTypes.string }; -const mapStateToProps = (state) => state.rooms; +const mapStateToProps = (state) => ({ + login_user_name: state.login.username, + rooms: state.rooms.rooms, + selected: state.rooms.selected +}); export default connect( mapStateToProps, diff --git a/src/styles/styles.scss b/src/styles/styles.scss index dc31882..0bd74df 100644 --- a/src/styles/styles.scss +++ b/src/styles/styles.scss @@ -41,6 +41,9 @@ header h1 { footer { display: flex; + padding: 0.5em; + width: 100%; + box-sizing: border-box; } main { @@ -69,20 +72,59 @@ main { } #room-chat { - flex: 3; + height: 100%; + width: 75%; display: flex; flex-flow: column; + justify-content: space-between; } #room-chat-header { + flex: 1; text-align: center; font-size: 1.3em; padding: 0.8em; border: solid grey 0.1em; } -#room-chat-messages { - flex: 1; +#room-chat-message-list { + display: block; + height: 84%; + width: 100%; + box-sizing: border-box; + margin: 0; + padding: 1em; + + overflow: auto; + + list-style: none; +} + +.room-chat-message { + display: flex; + flex-flow: column; + align-items: flex-start; +} + +.room-chat-message-me { + align-items: flex-end; +} + +.room-chat-message-user { + font-weight: bold; + color: blue; +} + +.room-chat-message-text { + padding: 0.5em 0.7em; + margin: 0.2em 0.5em; + border-radius: 0.8em; + background-color: lightgrey; +} + +.room-chat-message-me > .room-chat-message-text { + background-color: blue; + color: white; } #room-chat-form {