You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB

  1. import Status from './status';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PureRenderMixin from 'react-addons-pure-render-mixin';
  4. import { ScrollContainer } from 'react-router-scroll';
  5. import StatusContainer from '../containers/status_container';
  6. import moment from 'moment';
  7. const StatusList = React.createClass({
  8. propTypes: {
  9. statusIds: ImmutablePropTypes.list.isRequired,
  10. onScrollToBottom: React.PropTypes.func,
  11. trackScroll: React.PropTypes.bool
  12. },
  13. getDefaultProps () {
  14. return {
  15. trackScroll: true
  16. };
  17. },
  18. getInitialState () {
  19. return {
  20. now: moment()
  21. };
  22. },
  23. mixins: [PureRenderMixin],
  24. componentDidMount () {
  25. this._interval = setInterval(() => this.setState({ now: moment() }), 60000);
  26. },
  27. componentWillUnmount () {
  28. clearInterval(this._interval);
  29. },
  30. handleScroll (e) {
  31. const { scrollTop, scrollHeight, clientHeight } = e.target;
  32. if (scrollTop === scrollHeight - clientHeight) {
  33. this.props.onScrollToBottom();
  34. }
  35. },
  36. render () {
  37. const { statusIds, onScrollToBottom, trackScroll } = this.props;
  38. const scrollableArea = (
  39. <div className='scrollable' onScroll={this.handleScroll}>
  40. <div>
  41. {statusIds.map((statusId) => {
  42. return <StatusContainer key={statusId} id={statusId} now={this.state.now} />;
  43. })}
  44. </div>
  45. </div>
  46. );
  47. if (trackScroll) {
  48. return (
  49. <ScrollContainer scrollKey='status-list'>
  50. {scrollableArea}
  51. </ScrollContainer>
  52. );
  53. } else {
  54. return scrollableArea;
  55. }
  56. }
  57. });
  58. export default StatusList;