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.

89 lines
2.4 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
  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import StatusListContainer from '../ui/containers/status_list_container';
  4. import Column from '../ui/components/column';
  5. import {
  6. refreshTimeline,
  7. updateTimeline,
  8. deleteFromTimelines
  9. } from '../../actions/timelines';
  10. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  11. import { FormattedMessage } from 'react-intl';
  12. import createStream from '../../stream';
  13. const mapStateToProps = state => ({
  14. hasUnread: state.getIn(['timelines', 'tag', 'unread']) > 0,
  15. accessToken: state.getIn(['meta', 'access_token'])
  16. });
  17. const HashtagTimeline = React.createClass({
  18. propTypes: {
  19. params: React.PropTypes.object.isRequired,
  20. dispatch: React.PropTypes.func.isRequired,
  21. accessToken: React.PropTypes.string.isRequired,
  22. hasUnread: React.PropTypes.bool
  23. },
  24. mixins: [PureRenderMixin],
  25. _subscribe (dispatch, id) {
  26. const { accessToken } = this.props;
  27. this.subscription = createStream(accessToken, `hashtag&tag=${id}`, {
  28. received (data) {
  29. switch(data.event) {
  30. case 'update':
  31. dispatch(updateTimeline('tag', JSON.parse(data.payload)));
  32. break;
  33. case 'delete':
  34. dispatch(deleteFromTimelines(data.payload));
  35. break;
  36. }
  37. }
  38. });
  39. },
  40. _unsubscribe () {
  41. if (typeof this.subscription !== 'undefined') {
  42. this.subscription.close();
  43. this.subscription = null;
  44. }
  45. },
  46. componentDidMount () {
  47. const { dispatch } = this.props;
  48. const { id } = this.props.params;
  49. dispatch(refreshTimeline('tag', id));
  50. this._subscribe(dispatch, id);
  51. },
  52. componentWillReceiveProps (nextProps) {
  53. if (nextProps.params.id !== this.props.params.id) {
  54. this.props.dispatch(refreshTimeline('tag', nextProps.params.id));
  55. this._unsubscribe();
  56. this._subscribe(this.props.dispatch, nextProps.params.id);
  57. }
  58. },
  59. componentWillUnmount () {
  60. this._unsubscribe();
  61. },
  62. render () {
  63. const { id, hasUnread } = this.props.params;
  64. return (
  65. <Column icon='hashtag' active={hasUnread} heading={id}>
  66. <ColumnBackButtonSlim />
  67. <StatusListContainer type='tag' id={id} emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />} />
  68. </Column>
  69. );
  70. },
  71. });
  72. export default connect(mapStateToProps)(HashtagTimeline);