闭社主体 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.

100 lines
3.1 KiB

7 years ago
7 years ago
7 years ago
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { expandHomeTimeline } from '../../actions/timelines';
  4. import PropTypes from 'prop-types';
  5. import StatusListContainer from '../ui/containers/status_list_container';
  6. import Column from '../../components/column';
  7. import ColumnHeader from '../../components/column_header';
  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 Link from 'react-router-dom/Link';
  12. const messages = defineMessages({
  13. title: { id: 'column.home', defaultMessage: 'Home' },
  14. });
  15. const mapStateToProps = state => ({
  16. hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0,
  17. hasFollows: state.getIn(['accounts_counters', state.getIn(['meta', 'me']), 'following_count']) > 0,
  18. });
  19. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class HomeTimeline extends React.PureComponent {
  22. static propTypes = {
  23. dispatch: PropTypes.func.isRequired,
  24. intl: PropTypes.object.isRequired,
  25. hasUnread: PropTypes.bool,
  26. hasFollows: PropTypes.bool,
  27. columnId: PropTypes.string,
  28. multiColumn: PropTypes.bool,
  29. };
  30. handlePin = () => {
  31. const { columnId, dispatch } = this.props;
  32. if (columnId) {
  33. dispatch(removeColumn(columnId));
  34. } else {
  35. dispatch(addColumn('HOME', {}));
  36. }
  37. }
  38. handleMove = (dir) => {
  39. const { columnId, dispatch } = this.props;
  40. dispatch(moveColumn(columnId, dir));
  41. }
  42. handleHeaderClick = () => {
  43. this.column.scrollTop();
  44. }
  45. setRef = c => {
  46. this.column = c;
  47. }
  48. handleLoadMore = () => {
  49. this.props.dispatch(expandHomeTimeline());
  50. }
  51. render () {
  52. const { intl, hasUnread, hasFollows, columnId, multiColumn } = this.props;
  53. const pinned = !!columnId;
  54. let emptyMessage;
  55. if (hasFollows) {
  56. emptyMessage = <FormattedMessage id='empty_column.home.inactivity' defaultMessage='Your home feed is empty. If you have been inactive for a while, it will be regenerated for you soon.' />;
  57. } else {
  58. emptyMessage = <FormattedMessage id='empty_column.home' defaultMessage="You aren't following anyone yet. Visit {public} or use search to get started and meet other users." values={{ public: <Link to='/timelines/public'><FormattedMessage id='empty_column.home.public_timeline' defaultMessage='the public timeline' /></Link> }} />;
  59. }
  60. return (
  61. <Column ref={this.setRef}>
  62. <ColumnHeader
  63. icon='home'
  64. active={hasUnread}
  65. title={intl.formatMessage(messages.title)}
  66. onPin={this.handlePin}
  67. onMove={this.handleMove}
  68. onClick={this.handleHeaderClick}
  69. pinned={pinned}
  70. multiColumn={multiColumn}
  71. >
  72. <ColumnSettingsContainer />
  73. </ColumnHeader>
  74. <StatusListContainer
  75. trackScroll={!pinned}
  76. scrollKey={`home_timeline-${columnId}`}
  77. loadMore={this.handleLoadMore}
  78. timelineId='home'
  79. emptyMessage={emptyMessage}
  80. />
  81. </Column>
  82. );
  83. }
  84. }