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.

109 lines
3.1 KiB

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