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.

73 lines
1.8 KiB

  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 { defineMessages, injectIntl } from 'react-intl';
  11. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  12. import createStream from '../../stream';
  13. const messages = defineMessages({
  14. title: { id: 'column.public', defaultMessage: 'Public' }
  15. });
  16. const mapStateToProps = state => ({
  17. accessToken: state.getIn(['meta', 'access_token'])
  18. });
  19. const PublicTimeline = React.createClass({
  20. propTypes: {
  21. dispatch: React.PropTypes.func.isRequired,
  22. intl: React.PropTypes.object.isRequired,
  23. accessToken: React.PropTypes.string.isRequired
  24. },
  25. mixins: [PureRenderMixin],
  26. componentDidMount () {
  27. const { dispatch, accessToken } = this.props;
  28. dispatch(refreshTimeline('public'));
  29. this.subscription = createStream(accessToken, 'public', {
  30. received (data) {
  31. switch(data.event) {
  32. case 'update':
  33. dispatch(updateTimeline('public', JSON.parse(data.payload)));
  34. break;
  35. case 'delete':
  36. dispatch(deleteFromTimelines(data.payload));
  37. break;
  38. }
  39. }
  40. });
  41. },
  42. componentWillUnmount () {
  43. if (typeof this.subscription !== 'undefined') {
  44. this.subscription.close();
  45. this.subscription = null;
  46. }
  47. },
  48. render () {
  49. const { intl } = this.props;
  50. return (
  51. <Column icon='globe' heading={intl.formatMessage(messages.title)}>
  52. <ColumnBackButtonSlim />
  53. <StatusListContainer type='public' />
  54. </Column>
  55. );
  56. },
  57. });
  58. export default connect(mapStateToProps)(injectIntl(PublicTimeline));