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.

82 lines
2.0 KiB

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