闭社主体 forked from https://github.com/tootsuite/mastodon
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.

107 lines
2.9 KiB

7 years ago
  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 {
  8. refreshPublicTimeline,
  9. expandPublicTimeline,
  10. } from '../../actions/timelines';
  11. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  12. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  13. import ColumnSettingsContainer from './containers/column_settings_container';
  14. import { connectPublicStream } from '../../actions/streaming';
  15. const messages = defineMessages({
  16. title: { id: 'column.public', defaultMessage: 'Federated timeline' },
  17. });
  18. const mapStateToProps = state => ({
  19. hasUnread: state.getIn(['timelines', 'public', 'unread']) > 0,
  20. });
  21. @connect(mapStateToProps)
  22. @injectIntl
  23. export default class PublicTimeline extends React.PureComponent {
  24. static propTypes = {
  25. dispatch: PropTypes.func.isRequired,
  26. intl: PropTypes.object.isRequired,
  27. columnId: PropTypes.string,
  28. multiColumn: PropTypes.bool,
  29. hasUnread: PropTypes.bool,
  30. };
  31. handlePin = () => {
  32. const { columnId, dispatch } = this.props;
  33. if (columnId) {
  34. dispatch(removeColumn(columnId));
  35. } else {
  36. dispatch(addColumn('PUBLIC', {}));
  37. }
  38. }
  39. handleMove = (dir) => {
  40. const { columnId, dispatch } = this.props;
  41. dispatch(moveColumn(columnId, dir));
  42. }
  43. handleHeaderClick = () => {
  44. this.column.scrollTop();
  45. }
  46. componentDidMount () {
  47. const { dispatch } = this.props;
  48. dispatch(refreshPublicTimeline());
  49. this.disconnect = dispatch(connectPublicStream());
  50. }
  51. componentWillUnmount () {
  52. if (this.disconnect) {
  53. this.disconnect();
  54. this.disconnect = null;
  55. }
  56. }
  57. setRef = c => {
  58. this.column = c;
  59. }
  60. handleLoadMore = () => {
  61. this.props.dispatch(expandPublicTimeline());
  62. }
  63. render () {
  64. const { intl, columnId, hasUnread, multiColumn } = this.props;
  65. const pinned = !!columnId;
  66. return (
  67. <Column ref={this.setRef}>
  68. <ColumnHeader
  69. icon='globe'
  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. timelineId='public'
  82. loadMore={this.handleLoadMore}
  83. trackScroll={!pinned}
  84. scrollKey={`public_timeline-${columnId}`}
  85. emptyMessage={<FormattedMessage id='empty_column.public' defaultMessage='There is nothing here! Write something publicly, or manually follow users from other instances to fill it up' />}
  86. />
  87. </Column>
  88. );
  89. }
  90. }