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.

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