now fetching and rendering messages
This commit is contained in:
+40
-27
@@ -65,7 +65,7 @@
|
|||||||
handleSubmit: function(e) {
|
handleSubmit: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({errorCleared: false, submitDisabled: true});
|
this.setState({errorCleared: false, submitDisabled: true});
|
||||||
this.props.onLogin(this.state.login, this.state.password);
|
this.props.onLogin(this.state.login.trim(), this.state.password.trim());
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var submitClassList = "btn btn-primary";
|
var submitClassList = "btn btn-primary";
|
||||||
@@ -524,21 +524,52 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab
|
|||||||
|
|
||||||
var MessagesView = React.createClass({
|
var MessagesView = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {messages: []};
|
return {
|
||||||
|
messages: [],
|
||||||
|
title: ''
|
||||||
|
};
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.setState({messages: messagesList});
|
this.propsChange(this.props);
|
||||||
|
},
|
||||||
|
componentWillReceiveProps: function(nextProps) {
|
||||||
|
this.propsChange(nextProps);
|
||||||
|
},
|
||||||
|
propsChange: function(props) {
|
||||||
|
var topic = Tinode.getTopic(props.topic);
|
||||||
|
// Clear messages cached in the component
|
||||||
|
this.setState({messages: []});
|
||||||
|
if (topic.isSubscribed()) {
|
||||||
|
this.handleInfoChange(topic);
|
||||||
|
} else {
|
||||||
|
topic.onData = this.handleNewMessage;
|
||||||
|
topic.onInfoChange = this.handleInfoChange;
|
||||||
|
topic.onSubsUpdated = this.handleSubsUpdated;
|
||||||
|
topic.subscribe({get: "info sub data"});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleInfoChange: function(info) {
|
||||||
|
console.log("handleInfoChange: " + info);
|
||||||
|
this.setState({title: info.public});
|
||||||
|
},
|
||||||
|
handleSubsUpdated: function(uids) {
|
||||||
|
|
||||||
|
},
|
||||||
|
handleNewMessage: function(msg) {
|
||||||
|
this.setState({messages: this.state.messages.concat(msg)});
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var me = Tinode.getCurrentUserID();
|
||||||
var messageNodes = this.state.messages.map(function(msg) {
|
var messageNodes = this.state.messages.map(function(msg) {
|
||||||
|
var isReply = !(msg.from === me);
|
||||||
return (
|
return (
|
||||||
<Message content={msg.content} timestamp={msg.timestamp} response={msg.response} key={msg.id} />
|
<Message content={msg.content} timestamp={msg.ts} response={isReply} key={msg.seq} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div className="panel panel-default fullViewPort" id="messagesPanel">
|
<div className="panel panel-default fullViewPort" id="messagesPanel">
|
||||||
<div className="panel-heading" id="chatTitle">
|
<div className="panel-heading" id="chatTitle">
|
||||||
<h3 className="panel-title">{this.props.topic}</h3>
|
<h3 className="panel-title">{this.state.title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="panel-body" id="messagesView">
|
<div className="panel-body" id="messagesView">
|
||||||
<ul className="chatBox">
|
<ul className="chatBox">
|
||||||
@@ -562,7 +593,7 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab
|
|||||||
sideTitle: 'not set',
|
sideTitle: 'not set',
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
errorText: '',
|
errorText: '',
|
||||||
selectedTopicName: '',
|
topicSelected: '',
|
||||||
loginDisabled: false,
|
loginDisabled: false,
|
||||||
subscriptions: {}
|
subscriptions: {}
|
||||||
};
|
};
|
||||||
@@ -591,16 +622,9 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab
|
|||||||
instance.setState({loginDisabled: false, errorText: err.message});
|
instance.setState({loginDisabled: false, errorText: err.message});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleInfoChange: function(info) {
|
|
||||||
console.log(info);
|
|
||||||
this.setState({selectedTopicName: info.public});
|
|
||||||
},
|
|
||||||
handleMeInfoChange: function(info) {
|
handleMeInfoChange: function(info) {
|
||||||
this.setState({sideTitle: info.public});
|
this.setState({sideTitle: info.public});
|
||||||
},
|
},
|
||||||
handleSubsUpdated: function(uids) {
|
|
||||||
console.log(uids);
|
|
||||||
},
|
|
||||||
handleMeSubsChange: function(sub) {
|
handleMeSubsChange: function(sub) {
|
||||||
var subs = this.state.subscriptions;
|
var subs = this.state.subscriptions;
|
||||||
subs[sub.topic] = sub;
|
subs[sub.topic] = sub;
|
||||||
@@ -608,20 +632,9 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab
|
|||||||
},
|
},
|
||||||
handleNewAccount: function(login_, password_, public_, private_) {
|
handleNewAccount: function(login_, password_, public_, private_) {
|
||||||
|
|
||||||
},
|
|
||||||
handleNewMessage: function(msg) {
|
|
||||||
console.log(msg);
|
|
||||||
},
|
},
|
||||||
handleTopicSelected: function(topicName) {
|
handleTopicSelected: function(topicName) {
|
||||||
var topic = Tinode.getTopic(topicName);
|
this.setState({topicSelected: topicName});
|
||||||
if (topic.isSubscribed()) {
|
|
||||||
this.handleInfoChange(topic);
|
|
||||||
} else {
|
|
||||||
topic.onData = this.handleNewMessage;
|
|
||||||
topic.onInfoChange = this.handleInfoChange;
|
|
||||||
topic.onSubsUpdated = this.handleSubsUpdated;
|
|
||||||
topic.subscribe({get: "info sub data"});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
handleSignUp: function() {
|
handleSignUp: function() {
|
||||||
this.setState({sidePanel: 'register'});
|
this.setState({sidePanel: 'register'});
|
||||||
@@ -659,8 +672,8 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab
|
|||||||
<div className="container-fluid fullHeight">
|
<div className="container-fluid fullHeight">
|
||||||
<div className="row fullHeight">
|
<div className="row fullHeight">
|
||||||
<div className="col-lg-12 fullHeight">
|
<div className="col-lg-12 fullHeight">
|
||||||
{this.state.selectedTopicName ?
|
{this.state.topicSelected ?
|
||||||
<MessagesView topic={this.state.selectedTopicName} /> :
|
<MessagesView topic={this.state.topicSelected} /> :
|
||||||
<DummyMessagesView />}
|
<DummyMessagesView />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user