Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature connect to api #27

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 55 additions & 30 deletions src/components/accountScreen/accountScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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 = {
Expand Down Expand Up @@ -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={{
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -231,13 +262,8 @@ class AccountScreen extends Component {

render() {
return (
<div className="auto">
<HeaderNav
pic={this.props.currentUser.userImg}
surname={this.props.currentUser.userSurname}
name={this.props.currentUser.userName}
/>

<div>
<HeaderNav pic={ this.props.currentUser.userImg } surname={ this.props.currentUser.userSurname } name={ this.props.currentUser.userName } />
<div className="leftPanelContainer">
<div className="searchContainer">
<SearchBar
Expand All @@ -246,14 +272,12 @@ class AccountScreen extends Component {
onChange={text => this.filterList(text)}
/>
</div>

<ul className="defaultList">
{this.props.filteredChats.map(chat => (
<li
data-category={chat}
key={chat}
onClick={() => this.changeSelected(chat)}
>
onClick={() => this.changeSelected(chat)}>
<ChatCard
title={chat.userName}
avatar={chat.userImg}
Expand All @@ -265,11 +289,11 @@ class AccountScreen extends Component {
</ul>
</div>

<div className="mainBubbleContainer">
{this.props.msgs.map(chat => {
<div id="theChat" className="mainBubbleContainer">
{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 (
<div className="bubbleContainer">
Expand All @@ -278,8 +302,8 @@ class AccountScreen extends Component {
</div>
);
} 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 (
<div className="bubbleContainer">
Expand Down Expand Up @@ -316,7 +340,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
getUser,
getUsers,
getCurrentUser,
changeUser,
addMsg,
Expand All @@ -327,7 +351,8 @@ const mapDispatchToProps = dispatch =>
getUserChats,
filterUserChats,
changeSelectedChat,
changeReciever
changeReciever,
updateMsgs
},
dispatch
);
Expand Down
Loading