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.

120 lines
3.5 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  4. import { NavLink } from 'react-router-dom';
  5. import PropTypes from 'prop-types';
  6. import StatusListContainer from '../ui/containers/status_list_container';
  7. import Column from '../../components/column';
  8. import ColumnHeader from '../../components/column_header';
  9. import { expandCommunityTimeline } from '../../actions/timelines';
  10. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  11. import ColumnSettingsContainer from './containers/column_settings_container';
  12. import { connectCommunityStream } from '../../actions/streaming';
  13. const messages = defineMessages({
  14. title: { id: 'column.community', defaultMessage: 'Local timeline' },
  15. });
  16. const mapStateToProps = (state, { onlyMedia }) => ({
  17. hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0,
  18. });
  19. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class CommunityTimeline extends React.PureComponent {
  22. static defaultProps = {
  23. onlyMedia: false,
  24. };
  25. static propTypes = {
  26. dispatch: PropTypes.func.isRequired,
  27. columnId: PropTypes.string,
  28. intl: PropTypes.object.isRequired,
  29. hasUnread: PropTypes.bool,
  30. multiColumn: PropTypes.bool,
  31. onlyMedia: PropTypes.bool,
  32. };
  33. handlePin = () => {
  34. const { columnId, dispatch } = this.props;
  35. if (columnId) {
  36. dispatch(removeColumn(columnId));
  37. } else {
  38. dispatch(addColumn('COMMUNITY', {}));
  39. }
  40. }
  41. handleMove = (dir) => {
  42. const { columnId, dispatch } = this.props;
  43. dispatch(moveColumn(columnId, dir));
  44. }
  45. handleHeaderClick = () => {
  46. this.column.scrollTop();
  47. }
  48. componentDidMount () {
  49. const { dispatch, onlyMedia } = this.props;
  50. dispatch(expandCommunityTimeline({ onlyMedia }));
  51. this.disconnect = dispatch(connectCommunityStream({ onlyMedia }));
  52. }
  53. componentWillUnmount () {
  54. if (this.disconnect) {
  55. this.disconnect();
  56. this.disconnect = null;
  57. }
  58. }
  59. setRef = c => {
  60. this.column = c;
  61. }
  62. handleLoadMore = maxId => {
  63. const { dispatch, onlyMedia } = this.props;
  64. dispatch(expandCommunityTimeline({ maxId, onlyMedia }));
  65. }
  66. render () {
  67. const { intl, hasUnread, columnId, multiColumn, onlyMedia } = this.props;
  68. const pinned = !!columnId;
  69. const headline = (
  70. <div className='community-timeline__section-headline'>
  71. <NavLink exact to='/timelines/public/local' replace><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
  72. <NavLink exact to='/timelines/public/local/media' replace><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
  73. </div>
  74. );
  75. return (
  76. <Column ref={this.setRef}>
  77. <ColumnHeader
  78. icon='users'
  79. active={hasUnread}
  80. title={intl.formatMessage(messages.title)}
  81. onPin={this.handlePin}
  82. onMove={this.handleMove}
  83. onClick={this.handleHeaderClick}
  84. pinned={pinned}
  85. multiColumn={multiColumn}
  86. >
  87. <ColumnSettingsContainer />
  88. </ColumnHeader>
  89. <StatusListContainer
  90. prepend={headline}
  91. trackScroll={!pinned}
  92. scrollKey={`community_timeline-${columnId}`}
  93. timelineId={`community${onlyMedia ? ':media' : ''}`}
  94. onLoadMore={this.handleLoadMore}
  95. emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
  96. />
  97. </Column>
  98. );
  99. }
  100. }