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.7 KiB

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. } from '../../actions/timelines';
  9. const HashtagTimeline = React.createClass({
  10. propTypes: {
  11. params: React.PropTypes.object.isRequired,
  12. dispatch: React.PropTypes.func.isRequired
  13. },
  14. mixins: [PureRenderMixin],
  15. _subscribe (dispatch, id) {
  16. if (typeof App !== 'undefined') {
  17. this.subscription = App.cable.subscriptions.create({
  18. channel: 'HashtagChannel',
  19. tag: id
  20. }, {
  21. received (data) {
  22. dispatch(updateTimeline('tag', JSON.parse(data.message)));
  23. }
  24. });
  25. }
  26. },
  27. _unsubscribe () {
  28. if (typeof this.subscription !== 'undefined') {
  29. this.subscription.unsubscribe();
  30. }
  31. },
  32. componentWillMount () {
  33. const { dispatch } = this.props;
  34. const { id } = this.props.params;
  35. dispatch(refreshTimeline('tag', true, id));
  36. this._subscribe(dispatch, id);
  37. },
  38. componentWillReceiveProps (nextProps) {
  39. if (nextProps.params.id !== this.props.params.id) {
  40. this.props.dispatch(refreshTimeline('tag', true, nextProps.params.id));
  41. this._unsubscribe();
  42. this._subscribe(this.props.dispatch, nextProps.params.id);
  43. }
  44. },
  45. componentWillUnmount () {
  46. this._unsubscribe();
  47. },
  48. render () {
  49. const { id } = this.props.params;
  50. return (
  51. <Column icon='hashtag' heading={id}>
  52. <StatusListContainer type='tag' id={id} />
  53. </Column>
  54. );
  55. },
  56. });
  57. export default connect()(HashtagTimeline);