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
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. class HomeTimeline extends React.PureComponent {
  20. static propTypes = {
  21. dispatch: PropTypes.func.isRequired,
  22. intl: PropTypes.object.isRequired,
  23. hasUnread: PropTypes.bool,
  24. hasFollows: PropTypes.bool,
  25. columnId: PropTypes.string,
  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('HOME', {}));
  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. setRef = c => {
  44. this.column = c;
  45. }
  46. handleLoadMore = () => {
  47. this.props.dispatch(expandHomeTimeline());
  48. }
  49. render () {
  50. const { intl, hasUnread, hasFollows, columnId, multiColumn } = this.props;
  51. const pinned = !!columnId;
  52. let emptyMessage;
  53. if (hasFollows) {
  54. 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.' />;
  55. } else {
  56. 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> }} />;
  57. }
  58. return (
  59. <Column ref={this.setRef}>
  60. <ColumnHeader
  61. icon='home'
  62. active={hasUnread}
  63. title={intl.formatMessage(messages.title)}
  64. onPin={this.handlePin}
  65. onMove={this.handleMove}
  66. onClick={this.handleHeaderClick}
  67. pinned={pinned}
  68. multiColumn={multiColumn}
  69. >
  70. <ColumnSettingsContainer />
  71. </ColumnHeader>
  72. <StatusListContainer
  73. trackScroll={!pinned}
  74. scrollKey={`home_timeline-${columnId}`}
  75. loadMore={this.handleLoadMore}
  76. timelineId='home'
  77. emptyMessage={emptyMessage}
  78. />
  79. </Column>
  80. );
  81. }
  82. }
  83. export default connect(mapStateToProps)(injectIntl(HomeTimeline));