logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

index.js (2921B)


  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import StatusListContainer from '../ui/containers/status_list_container';
  5. import Column from '../../components/column';
  6. import ColumnHeader from '../../components/column_header';
  7. import { expandCommunityTimeline } from '../../actions/timelines';
  8. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  9. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  10. import ColumnSettingsContainer from './containers/column_settings_container';
  11. import { connectCommunityStream } from '../../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. render () {
  61. const { intl, hasUnread, columnId, multiColumn } = this.props;
  62. const pinned = !!columnId;
  63. return (
  64. <Column ref={this.setRef}>
  65. <ColumnHeader
  66. icon='users'
  67. active={hasUnread}
  68. title={intl.formatMessage(messages.title)}
  69. onPin={this.handlePin}
  70. onMove={this.handleMove}
  71. onClick={this.handleHeaderClick}
  72. pinned={pinned}
  73. multiColumn={multiColumn}
  74. >
  75. <ColumnSettingsContainer />
  76. </ColumnHeader>
  77. <StatusListContainer
  78. trackScroll={!pinned}
  79. scrollKey={`community_timeline-${columnId}`}
  80. timelineId='community'
  81. onLoadMore={this.handleLoadMore}
  82. emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
  83. />
  84. </Column>
  85. );
  86. }
  87. }