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.

69 lines
1.7 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. const StatusList = React.createClass({
  7. propTypes: {
  8. statusIds: ImmutablePropTypes.list.isRequired,
  9. onScrollToBottom: React.PropTypes.func,
  10. trackScroll: React.PropTypes.bool
  11. },
  12. getDefaultProps () {
  13. return {
  14. trackScroll: true
  15. };
  16. },
  17. mixins: [PureRenderMixin],
  18. handleScroll (e) {
  19. const { scrollTop, scrollHeight, clientHeight } = e.target;
  20. this._oldScrollPosition = scrollHeight - scrollTop;
  21. if (scrollTop === scrollHeight - clientHeight) {
  22. this.props.onScrollToBottom();
  23. }
  24. },
  25. componentDidUpdate (prevProps) {
  26. if (prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && this._oldScrollPosition) {
  27. const node = ReactDOM.findDOMNode(this);
  28. if (node.scrollTop > 0) {
  29. node.scrollTop = node.scrollHeight - this._oldScrollPosition;
  30. }
  31. }
  32. },
  33. render () {
  34. const { statusIds, onScrollToBottom, trackScroll } = this.props;
  35. const scrollableArea = (
  36. <div className='scrollable' onScroll={this.handleScroll}>
  37. <div>
  38. {statusIds.map((statusId) => {
  39. return <StatusContainer key={statusId} id={statusId} />;
  40. })}
  41. </div>
  42. </div>
  43. );
  44. if (trackScroll) {
  45. return (
  46. <ScrollContainer scrollKey='status-list'>
  47. {scrollableArea}
  48. </ScrollContainer>
  49. );
  50. } else {
  51. return scrollableArea;
  52. }
  53. }
  54. });
  55. export default StatusList;