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.

63 lines
1.5 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. const messages = defineMessages({
  12. title: { id: 'column.public', defaultMessage: 'Public' }
  13. });
  14. const PublicTimeline = React.createClass({
  15. propTypes: {
  16. dispatch: React.PropTypes.func.isRequired
  17. },
  18. mixins: [PureRenderMixin],
  19. componentWillMount () {
  20. const { dispatch } = this.props;
  21. dispatch(refreshTimeline('public'));
  22. if (typeof App !== 'undefined') {
  23. this.subscription = App.cable.subscriptions.create('PublicChannel', {
  24. received (data) {
  25. switch(data.type) {
  26. case 'update':
  27. return dispatch(updateTimeline('public', JSON.parse(data.message)));
  28. case 'delete':
  29. return dispatch(deleteFromTimelines(data.id));
  30. }
  31. }
  32. });
  33. }
  34. },
  35. componentWillUnmount () {
  36. if (typeof this.subscription !== 'undefined') {
  37. this.subscription.unsubscribe();
  38. }
  39. },
  40. render () {
  41. const { intl } = this.props;
  42. return (
  43. <Column icon='globe' heading={intl.formatMessage(messages.title)}>
  44. <StatusListContainer type='public' />
  45. </Column>
  46. );
  47. },
  48. });
  49. export default connect()(injectIntl(PublicTimeline));