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

95 lines
2.9 KiB

7 years ago
7 years ago
7 years ago
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 { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  8. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  9. import ColumnSettingsContainer from './containers/column_settings_container';
  10. import Link from 'react-router/lib/Link';
  11. const messages = defineMessages({
  12. title: { id: 'column.home', defaultMessage: 'Home' },
  13. });
  14. const mapStateToProps = state => ({
  15. hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0,
  16. hasFollows: state.getIn(['accounts_counters', state.getIn(['meta', 'me']), 'following_count']) > 0,
  17. });
  18. class HomeTimeline extends React.PureComponent {
  19. static propTypes = {
  20. dispatch: PropTypes.func.isRequired,
  21. intl: PropTypes.object.isRequired,
  22. hasUnread: PropTypes.bool,
  23. hasFollows: PropTypes.bool,
  24. columnId: PropTypes.string,
  25. multiColumn: PropTypes.bool,
  26. };
  27. handlePin = () => {
  28. const { columnId, dispatch } = this.props;
  29. if (columnId) {
  30. dispatch(removeColumn(columnId));
  31. } else {
  32. dispatch(addColumn('HOME', {}));
  33. }
  34. }
  35. handleMove = (dir) => {
  36. const { columnId, dispatch } = this.props;
  37. dispatch(moveColumn(columnId, dir));
  38. }
  39. handleHeaderClick = () => {
  40. this.column.scrollTop();
  41. }
  42. setRef = c => {
  43. this.column = c;
  44. }
  45. render () {
  46. const { intl, hasUnread, hasFollows, columnId, multiColumn } = this.props;
  47. const pinned = !!columnId;
  48. let emptyMessage;
  49. if (hasFollows) {
  50. 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.' />;
  51. } else {
  52. 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> }} />;
  53. }
  54. return (
  55. <Column ref={this.setRef}>
  56. <ColumnHeader
  57. icon='home'
  58. active={hasUnread}
  59. title={intl.formatMessage(messages.title)}
  60. onPin={this.handlePin}
  61. onMove={this.handleMove}
  62. onClick={this.handleHeaderClick}
  63. pinned={pinned}
  64. multiColumn={multiColumn}
  65. >
  66. <ColumnSettingsContainer />
  67. </ColumnHeader>
  68. <StatusListContainer
  69. {...this.props}
  70. trackScroll={!pinned}
  71. scrollKey={`home_timeline-${columnId}`}
  72. type='home'
  73. emptyMessage={emptyMessage}
  74. />
  75. </Column>
  76. );
  77. }
  78. }
  79. export default connect(mapStateToProps)(injectIntl(HomeTimeline));