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.

94 lines
2.5 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. hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
  18. });
  19. @connect(mapStateToProps)
  20. @injectIntl
  21. export default class Favourites extends ImmutablePureComponent {
  22. static propTypes = {
  23. dispatch: PropTypes.func.isRequired,
  24. statusIds: ImmutablePropTypes.list.isRequired,
  25. intl: PropTypes.object.isRequired,
  26. columnId: PropTypes.string,
  27. multiColumn: PropTypes.bool,
  28. hasMore: PropTypes.bool,
  29. };
  30. componentWillMount () {
  31. this.props.dispatch(fetchFavouritedStatuses());
  32. }
  33. handlePin = () => {
  34. const { columnId, dispatch } = this.props;
  35. if (columnId) {
  36. dispatch(removeColumn(columnId));
  37. } else {
  38. dispatch(addColumn('FAVOURITES', {}));
  39. }
  40. }
  41. handleMove = (dir) => {
  42. const { columnId, dispatch } = this.props;
  43. dispatch(moveColumn(columnId, dir));
  44. }
  45. handleHeaderClick = () => {
  46. this.column.scrollTop();
  47. }
  48. setRef = c => {
  49. this.column = c;
  50. }
  51. handleScrollToBottom = () => {
  52. this.props.dispatch(expandFavouritedStatuses());
  53. }
  54. render () {
  55. const { intl, statusIds, columnId, multiColumn, hasMore } = this.props;
  56. const pinned = !!columnId;
  57. return (
  58. <Column ref={this.setRef}>
  59. <ColumnHeader
  60. icon='star'
  61. title={intl.formatMessage(messages.heading)}
  62. onPin={this.handlePin}
  63. onMove={this.handleMove}
  64. onClick={this.handleHeaderClick}
  65. pinned={pinned}
  66. multiColumn={multiColumn}
  67. showBackButton
  68. />
  69. <StatusList
  70. trackScroll={!pinned}
  71. statusIds={statusIds}
  72. scrollKey={`favourited_statuses-${columnId}`}
  73. hasMore={hasMore}
  74. onScrollToBottom={this.handleScrollToBottom}
  75. />
  76. </Column>
  77. );
  78. }
  79. }