twister-react/jsx/profile/Mentions.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-04-29 11:19:10 +02:00
var React = require('react');
var MiniProfile = require("../common/MiniProfile.js");
var Postboard = require("../common/Postboard.js");
var SetIntervalMixin = require("../common/SetIntervalMixin.js");
var StreamMixin = require("../common/StreamMixin.js");
var SafeStateChangeMixin = require('../common/SafeStateChangeMixin.js');
var EventListenerMixin = require('../common/EventListenerMixin.js');
2015-04-30 11:22:58 +02:00
var AppSettingsMixin = require('../common/AppSettingsMixin.js');
2015-04-29 11:19:10 +02:00
2015-04-30 11:22:58 +02:00
module.exports = Mentions = React.createClass({
2015-04-29 11:19:10 +02:00
2015-04-30 11:22:58 +02:00
mixins: [StreamMixin,AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
2015-04-29 11:19:10 +02:00
contextTypes: {
router: React.PropTypes.func
},
getInitialState: function() {
return {
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
data: [],
2015-04-30 11:22:58 +02:00
postIdentifiers: {},
loading: true
2015-04-29 11:19:10 +02:00
};
},
updateMentions: function(outdatedLimit) {
thisComponent=this;
2015-04-30 11:22:58 +02:00
if (outdatedLimit===undefined) {outdatedLimit=this.state.appSettings.pollInterval/2;}
2015-04-29 11:19:10 +02:00
Twister.getUser(this.state.username).doMentions(function(mentions){
for(var i in mentions){
thisComponent.addPost(mentions[i]);
}
2015-04-30 11:22:58 +02:00
thisComponent.setStateSafe({loading: false});
2015-04-29 11:19:10 +02:00
},{outdatedLimit: outdatedLimit});
},
componentDidMount: function() {
2015-04-30 11:22:58 +02:00
this.updateMentions(this.state.appSettings.pollInterval*2);
2015-04-29 11:19:10 +02:00
2015-04-30 11:22:58 +02:00
this.setInterval(this.updateMentions, this.state.appSettings.pollInterval*1000);
2015-04-29 11:19:10 +02:00
},
render: function() {
return (
2015-04-30 11:22:58 +02:00
<Postboard data={this.state.data} loading={this.state.loading}/>
2015-04-29 11:19:10 +02:00
);
}
});