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.

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