diff --git a/package-lock.json b/package-lock.json index 19199bd..be053f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2675,7 +2675,7 @@ "es6-error": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", - "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==" + "integrity": "sha1-njr0B0Wd7tR+mpH5uIWoTrBcVh0=" }, "es6-iterator": { "version": "2.0.3", @@ -7519,7 +7519,7 @@ "react-material-ui-form-validator": { "version": "2.0.0-beta.3", "resolved": "https://registry.npmjs.org/react-material-ui-form-validator/-/react-material-ui-form-validator-2.0.0-beta.3.tgz", - "integrity": "sha512-qEvzfH63b5mGIJN4KDww2jbqEu3KM1yInL9ZL54nmpn68S0ClpbjtZp4YNwHos24AajV4ABolDebL1HmbGbkPA==" + "integrity": "sha1-S+x23BQoW08dg1tjuAQnUrWJV0c=" }, "react-redux": { "version": "5.0.6", @@ -7830,7 +7830,7 @@ "redux-form": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/redux-form/-/redux-form-7.2.0.tgz", - "integrity": "sha512-qbgeI19drwnm9FeGAotDA1vsZO8q94XF7IxPDuJmSXxDYX2rqzhND6NROahCBJfBK5xM1cchvmgscO2rry1EEw==", + "integrity": "sha1-RGXZvIY+QLFwRpXWcr6nX8+B2wQ=", "requires": { "deep-equal": "1.0.1", "es6-error": "4.1.1", diff --git a/src/components/accountScreen/accountScreen.js b/src/components/accountScreen/accountScreen.js index d23cc94..4b6950b 100644 --- a/src/components/accountScreen/accountScreen.js +++ b/src/components/accountScreen/accountScreen.js @@ -7,8 +7,10 @@ import HeaderNav from '../headerNav/headerNav'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; +import FlatButton from 'material-ui/FlatButton/FlatButton'; + import { - getUser, + getUsers, changeUser, getCurrentUser, registerUser, @@ -19,7 +21,7 @@ import { changeReciever } from '../../reducers/Account'; -import { addMsg, getMsgs, getChats } from '../../reducers/Chat'; +import { addMsg, getMsgs, getChats, updateMsgs } from '../../reducers/Chat'; const ChatBubbleRightStyle = { backgroundColor: '#007D80', @@ -42,11 +44,15 @@ const getShort = str => { }; const getShortTime = str => { - var value = str.getMinutes().toString(); - if (value.length === 1) { - value += '0'; + try{ + var fullTime = str.split('T')[1]; + var hour = fullTime.split(':')[0]; + var minute = fullTime.split(':')[1]; + return hour + ":" + minute; + }catch(ex){ + return "-----"; } - return str.getHours() + ':' + value; + }; const cardHeaderStyle = { @@ -150,12 +156,20 @@ const NewText = function(props) { hintText="Insert Text Message Here" onKeyDown={e => { if (e.key === 'Enter' && e.target.value.length > 0) { + props.addMsg( e.target.value, props.currentUser.userID, props.receiver.userID ); + + props.getUserChats(props.currentUser.userID); + e.target.value = ''; + setTimeout(function () { + var objDiv = document.getElementById("theChat"); + objDiv.scrollTop = objDiv.scrollHeight; + }, 1); } }} style={{ @@ -187,17 +201,32 @@ const MessageTimeRight = function(props) { class AccountScreen extends Component { constructor(props) { super(props); - try { + try{ props.getCurrentUser(); - } catch (exc) { - window.location.href = '/'; + var id = props.currentUser.userID; + props.getUsers(); + props.getUserChats(id); + + setInterval(()=>{ + try{ + props.getMsgs(props.currentUser.userID, props.receiver.userID); + props.updateMsgs(props.currentUser.userID,props.receiver.userID); + }catch(exc){ + + } + },500) + } + catch(exc){ + window.location.href = '/'; } - - props.getUserChats(this.props.allMsgs); - props.getMsgs(props.currentUser.userID, props.receiver.userID); this.filterList = this.filterList.bind(this); //this.state = { initialItems: initialItems, items: initialItems }; + + } + + componentWillReceiveProps(newProps) { + console.log(newProps); } filterList = function(text) { @@ -212,6 +241,8 @@ class AccountScreen extends Component { let userID = chat.userID; let tempChats = this.props.filteredChats; + console.log(userID + " is thier ID") + for (let i = 0; i < tempChats.length; i++) { tempChats[i].selected = false; } @@ -231,13 +262,8 @@ class AccountScreen extends Component { render() { return ( -
- - +
+
this.filterList(text)} />
-
    {this.props.filteredChats.map(chat => (
  • this.changeSelected(chat)} - > + onClick={() => this.changeSelected(chat)}>
-
- {this.props.msgs.map(chat => { +
+ {this.props.msgs.map(chat => { if ( - chat.senderID === this.props.currentUser.userID && - chat.receiverID === this.props.receiver.userID + chat.senderId === this.props.currentUser.userID && + chat.receiverId === this.props.receiver.userID ) { return (
@@ -278,8 +302,8 @@ class AccountScreen extends Component {
); } else if ( - chat.senderID === this.props.receiver.userID && - chat.receiverID === this.props.currentUser.userID + chat.senderId === this.props.receiver.userID && + chat.receiverId === this.props.currentUser.userID ) { return (
@@ -316,7 +340,7 @@ const mapStateToProps = state => { const mapDispatchToProps = dispatch => bindActionCreators( { - getUser, + getUsers, getCurrentUser, changeUser, addMsg, @@ -327,7 +351,8 @@ const mapDispatchToProps = dispatch => getUserChats, filterUserChats, changeSelectedChat, - changeReciever + changeReciever, + updateMsgs }, dispatch ); diff --git a/src/components/headerNav/headerNav.js b/src/components/headerNav/headerNav.js index 6523c24..7691799 100644 --- a/src/components/headerNav/headerNav.js +++ b/src/components/headerNav/headerNav.js @@ -1,147 +1,255 @@ -import './headerNav.css'; -import React, { Component } from 'react'; -import { bindActionCreators } from 'redux'; -import { connect } from 'react-redux'; -import { push } from 'react-router-redux'; -import { Route } from 'react-router-dom'; -import IconButton from 'material-ui/IconButton'; -import IconMenu from 'material-ui/IconMenu'; -import MenuItem from 'material-ui/MenuItem'; - -import { - getUser, - changeUser, - getCurrentUser, - registerUser, - loginUser, - logOut -} from '../../reducers/Account'; - -import { addMsg, getMsgs, getChats } from '../../reducers/Chat'; - -class HeaderNav extends Component { - constructor(props) { - super(props); - this.props = props; - try { - props.getCurrentUser(); - } catch (exc) { - window.location.href = '/'; - } - } - - handleChange = (event, logged) => { - this.setState({ logged: logged }); - }; - - changePage(value) { - push('/' + value); - } - - styles = { - 'padding-bottom': '2px' - }; - - render() { - return ( -