logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

index.js (3116B)


  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. @connect(mapStateToProps)
  15. export default class HashtagTimeline extends React.PureComponent {
  16. static propTypes = {
  17. params: PropTypes.object.isRequired,
  18. columnId: PropTypes.string,
  19. dispatch: PropTypes.func.isRequired,
  20. hasUnread: PropTypes.bool,
  21. multiColumn: PropTypes.bool,
  22. };
  23. handlePin = () => {
  24. const { columnId, dispatch } = this.props;
  25. if (columnId) {
  26. dispatch(removeColumn(columnId));
  27. } else {
  28. dispatch(addColumn('HASHTAG', { id: this.props.params.id }));
  29. }
  30. }
  31. handleMove = (dir) => {
  32. const { columnId, dispatch } = this.props;
  33. dispatch(moveColumn(columnId, dir));
  34. }
  35. handleHeaderClick = () => {
  36. this.column.scrollTop();
  37. }
  38. _subscribe (dispatch, id) {
  39. this.disconnect = dispatch(connectHashtagStream(id));
  40. }
  41. _unsubscribe () {
  42. if (this.disconnect) {
  43. this.disconnect();
  44. this.disconnect = null;
  45. }
  46. }
  47. componentDidMount () {
  48. const { dispatch } = this.props;
  49. const { id } = this.props.params;
  50. dispatch(expandHashtagTimeline(id));
  51. this._subscribe(dispatch, id);
  52. }
  53. componentWillReceiveProps (nextProps) {
  54. if (nextProps.params.id !== this.props.params.id) {
  55. this.props.dispatch(expandHashtagTimeline(nextProps.params.id));
  56. this._unsubscribe();
  57. this._subscribe(this.props.dispatch, nextProps.params.id);
  58. }
  59. }
  60. componentWillUnmount () {
  61. this._unsubscribe();
  62. }
  63. setRef = c => {
  64. this.column = c;
  65. }
  66. handleLoadMore = maxId => {
  67. this.props.dispatch(expandHashtagTimeline(this.props.params.id, { maxId }));
  68. }
  69. render () {
  70. const { hasUnread, columnId, multiColumn } = this.props;
  71. const { id } = this.props.params;
  72. const pinned = !!columnId;
  73. return (
  74. <Column ref={this.setRef}>
  75. <ColumnHeader
  76. icon='hashtag'
  77. active={hasUnread}
  78. title={id}
  79. onPin={this.handlePin}
  80. onMove={this.handleMove}
  81. onClick={this.handleHeaderClick}
  82. pinned={pinned}
  83. multiColumn={multiColumn}
  84. showBackButton
  85. />
  86. <StatusListContainer
  87. trackScroll={!pinned}
  88. scrollKey={`hashtag_timeline-${columnId}`}
  89. timelineId={`hashtag:${id}`}
  90. onLoadMore={this.handleLoadMore}
  91. emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />}
  92. />
  93. </Column>
  94. );
  95. }
  96. }