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

90 lines
2.4 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
  6. import Column from '../ui/components/column';
  7. import ColumnHeader from '../../components/column_header';
  8. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  9. import StatusList from '../../components/status_list';
  10. import { defineMessages, injectIntl } from 'react-intl';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. const messages = defineMessages({
  13. heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
  14. });
  15. const mapStateToProps = state => ({
  16. statusIds: state.getIn(['status_lists', 'favourites', 'items']),
  17. });
  18. @connect(mapStateToProps)
  19. @injectIntl
  20. export default class Favourites extends ImmutablePureComponent {
  21. static propTypes = {
  22. dispatch: PropTypes.func.isRequired,
  23. statusIds: ImmutablePropTypes.list.isRequired,
  24. intl: PropTypes.object.isRequired,
  25. columnId: PropTypes.string,
  26. multiColumn: PropTypes.bool,
  27. };
  28. componentWillMount () {
  29. this.props.dispatch(fetchFavouritedStatuses());
  30. }
  31. handlePin = () => {
  32. const { columnId, dispatch } = this.props;
  33. if (columnId) {
  34. dispatch(removeColumn(columnId));
  35. } else {
  36. dispatch(addColumn('FAVOURITES', {}));
  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. setRef = c => {
  47. this.column = c;
  48. }
  49. handleScrollToBottom = () => {
  50. this.props.dispatch(expandFavouritedStatuses());
  51. }
  52. render () {
  53. const { intl, statusIds, columnId, multiColumn } = this.props;
  54. const pinned = !!columnId;
  55. return (
  56. <Column ref={this.setRef}>
  57. <ColumnHeader
  58. icon='star'
  59. title={intl.formatMessage(messages.heading)}
  60. onPin={this.handlePin}
  61. onMove={this.handleMove}
  62. onClick={this.handleHeaderClick}
  63. pinned={pinned}
  64. multiColumn={multiColumn}
  65. />
  66. <StatusList
  67. trackScroll={!pinned}
  68. statusIds={statusIds}
  69. scrollKey={`favourited_statuses-${columnId}`}
  70. onScrollToBottom={this.handleScrollToBottom}
  71. />
  72. </Column>
  73. );
  74. }
  75. }