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.

75 lines
2.2 KiB

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 { defineMessages, injectIntl, FormattedMessage } 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.community', defaultMessage: 'Local' }
  15. });
  16. const mapStateToProps = state => ({
  17. hasUnread: state.getIn(['timelines', 'public', 'unread']) > 0,
  18. accessToken: state.getIn(['meta', 'access_token'])
  19. });
  20. const CommunityTimeline = React.createClass({
  21. propTypes: {
  22. dispatch: React.PropTypes.func.isRequired,
  23. intl: React.PropTypes.object.isRequired,
  24. accessToken: React.PropTypes.string.isRequired,
  25. hasUnread: React.PropTypes.bool
  26. },
  27. mixins: [PureRenderMixin],
  28. componentDidMount () {
  29. const { dispatch, accessToken } = this.props;
  30. dispatch(refreshTimeline('community'));
  31. this.subscription = createStream(accessToken, 'public:local', {
  32. received (data) {
  33. switch(data.event) {
  34. case 'update':
  35. dispatch(updateTimeline('community', JSON.parse(data.payload)));
  36. break;
  37. case 'delete':
  38. dispatch(deleteFromTimelines(data.payload));
  39. break;
  40. }
  41. }
  42. });
  43. },
  44. componentWillUnmount () {
  45. if (typeof this.subscription !== 'undefined') {
  46. this.subscription.close();
  47. this.subscription = null;
  48. }
  49. },
  50. render () {
  51. const { intl, hasUnread } = this.props;
  52. return (
  53. <Column icon='users' active={hasUnread} heading={intl.formatMessage(messages.title)}>
  54. <ColumnBackButtonSlim />
  55. <StatusListContainer type='community' emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />} />
  56. </Column>
  57. );
  58. },
  59. });
  60. export default connect(mapStateToProps)(injectIntl(CommunityTimeline));