twister-react/jsx/profile/Followings.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-04-29 11:19:10 +02:00
var React = require('react/addons');
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var MiniProfile = require("../common/MiniProfile.js");
2015-04-30 11:22:58 +02:00
var ProfileBoard = require("../common/ProfileBoard.js");
2015-04-29 11:19:10 +02:00
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
var ReactBootstrap = require('react-bootstrap')
, NavItem = ReactBootstrap.NavItem
, Nav = ReactBootstrap.Nav
, ListGroup = ReactBootstrap.ListGroup
, ListGroupItem = ReactBootstrap.ListGroupItem
, Panel = ReactBootstrap.Panel
, Glyphicon = ReactBootstrap.Glyphicon
, Button = ReactBootstrap.Button
2015-04-30 11:22:58 +02:00
module.exports = Followings = React.createClass({
2015-04-29 11:19:10 +02:00
2015-04-30 11:22:58 +02:00
mixins: [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),
2015-04-30 11:22:58 +02:00
followings: [],
loading: true
2015-04-29 11:19:10 +02:00
};
},
updateFollowings: function(outdatedLimit) {
thisComponent=this;
2015-04-30 11:22:58 +02:00
if (!outdatedLimit) {outdatedLimit=this.state.appSettings.pollInterval/2;}
2015-04-29 11:19:10 +02:00
Twister.getUser(this.state.username).doFollowings(function(followings){
thisComponent.setStateSafe(function(state){
var newfollowings = [];
for(var i in followings){
newfollowings.push(followings[i].getUsername());
}
state.followings = newfollowings;
2015-04-30 11:22:58 +02:00
state.loading = false;
2015-04-29 11:19:10 +02:00
return state;
});
2015-04-30 11:22:58 +02:00
2015-04-29 11:19:10 +02:00
},{outdatedLimit: outdatedLimit});
},
componentDidMount: function() {
2015-04-30 11:22:58 +02:00
this.updateFollowings(this.state.appSettings.pollInterval*2);
2015-04-29 11:19:10 +02:00
2015-04-30 11:22:58 +02:00
this.setInterval(this.updateFollowings, this.state.appSettings.pollInterval*1000);
2015-04-29 11:19:10 +02:00
},
render: function() {
return (
2015-04-30 11:22:58 +02:00
<ProfileBoard
loading={this.state.loading}
data={this.state.followings}
/>
2015-04-29 11:19:10 +02:00
);
2015-04-30 11:22:58 +02:00
2015-04-29 11:19:10 +02:00
}
2015-04-30 11:22:58 +02:00
2015-04-29 11:19:10 +02:00
});