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.

117 lines
3.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import StatusListContainer from '../ui/containers/status_list_container';
  5. import Column from '../../components/column';
  6. import ColumnHeader from '../../components/column_header';
  7. import { expandHashtagTimeline } from '../../actions/timelines';
  8. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  9. import { FormattedMessage } from 'react-intl';
  10. import { connectHashtagStream } from '../../actions/streaming';
  11. const mapStateToProps = (state, props) => ({
  12. hasUnread: state.getIn(['timelines', `hashtag:${props.params.id}`, 'unread']) > 0,
  13. });
  14. export default @connect(mapStateToProps)
  15. class HashtagTimeline extends React.PureComponent {
  16. static propTypes = {
  17. params: PropTypes.object.isRequired,
  18. columnId: PropTypes.string,
  19. dispatch: PropTypes.func.isRequired,
  20. shouldUpdateScroll: PropTypes.func,
  21. hasUnread: PropTypes.bool,
  22. multiColumn: PropTypes.bool,
  23. };
  24. handlePin = () => {
  25. const { columnId, dispatch } = this.props;
  26. if (columnId) {
  27. dispatch(removeColumn(columnId));
  28. } else {
  29. dispatch(addColumn('HASHTAG', { id: this.props.params.id }));
  30. }
  31. }
  32. handleMove = (dir) => {
  33. const { columnId, dispatch } = this.props;
  34. dispatch(moveColumn(columnId, dir));
  35. }
  36. handleHeaderClick = () => {
  37. this.column.scrollTop();
  38. }
  39. _subscribe (dispatch, id) {
  40. this.disconnect = dispatch(connectHashtagStream(id));
  41. }
  42. _unsubscribe () {
  43. if (this.disconnect) {
  44. this.disconnect();
  45. this.disconnect = null;
  46. }
  47. }
  48. componentDidMount () {
  49. const { dispatch } = this.props;
  50. const { id } = this.props.params;
  51. dispatch(expandHashtagTimeline(id));
  52. this._subscribe(dispatch, id);
  53. }
  54. componentWillReceiveProps (nextProps) {
  55. if (nextProps.params.id !== this.props.params.id) {
  56. this.props.dispatch(expandHashtagTimeline(nextProps.params.id));
  57. this._unsubscribe();
  58. this._subscribe(this.props.dispatch, nextProps.params.id);
  59. }
  60. }
  61. componentWillUnmount () {
  62. this._unsubscribe();
  63. }
  64. setRef = c => {
  65. this.column = c;
  66. }
  67. handleLoadMore = maxId => {
  68. this.props.dispatch(expandHashtagTimeline(this.props.params.id, { maxId }));
  69. }
  70. render () {
  71. const { shouldUpdateScroll, hasUnread, columnId, multiColumn } = this.props;
  72. const { id } = this.props.params;
  73. const pinned = !!columnId;
  74. return (
  75. <Column ref={this.setRef} label={`#${id}`}>
  76. <ColumnHeader
  77. icon='hashtag'
  78. active={hasUnread}
  79. title={id}
  80. onPin={this.handlePin}
  81. onMove={this.handleMove}
  82. onClick={this.handleHeaderClick}
  83. pinned={pinned}
  84. multiColumn={multiColumn}
  85. showBackButton
  86. />
  87. <StatusListContainer
  88. trackScroll={!pinned}
  89. scrollKey={`hashtag_timeline-${columnId}`}
  90. timelineId={`hashtag:${id}`}
  91. onLoadMore={this.handleLoadMore}
  92. emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />}
  93. shouldUpdateScroll={shouldUpdateScroll}
  94. />
  95. </Column>
  96. );
  97. }
  98. }