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.

90 lines
2.7 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 'themes/glitch/actions/timelines';
  4. import PropTypes from 'prop-types';
  5. import StatusListContainer from 'themes/glitch/features/ui/containers/status_list_container';
  6. import Column from 'themes/glitch/components/column';
  7. import ColumnHeader from 'themes/glitch/components/column_header';
  8. import { addColumn, removeColumn, moveColumn } from 'themes/glitch/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';
  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. });
  18. @connect(mapStateToProps)
  19. @injectIntl
  20. export default class HomeTimeline extends React.PureComponent {
  21. static propTypes = {
  22. dispatch: PropTypes.func.isRequired,
  23. intl: PropTypes.object.isRequired,
  24. hasUnread: 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, columnId, multiColumn } = this.props;
  51. const pinned = !!columnId;
  52. return (
  53. <Column ref={this.setRef} name='home'>
  54. <ColumnHeader
  55. icon='home'
  56. active={hasUnread}
  57. title={intl.formatMessage(messages.title)}
  58. onPin={this.handlePin}
  59. onMove={this.handleMove}
  60. onClick={this.handleHeaderClick}
  61. pinned={pinned}
  62. multiColumn={multiColumn}
  63. >
  64. <ColumnSettingsContainer />
  65. </ColumnHeader>
  66. <StatusListContainer
  67. trackScroll={!pinned}
  68. scrollKey={`home_timeline-${columnId}`}
  69. loadMore={this.handleLoadMore}
  70. timelineId='home'
  71. emptyMessage={<FormattedMessage id='empty_column.home' defaultMessage='Your home timeline is empty! 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> }} />}
  72. />
  73. </Column>
  74. );
  75. }
  76. }