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.

104 lines
3.2 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 { fetchBookmarkedStatuses, expandBookmarkedStatuses } from '../../actions/bookmarks';
  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, FormattedMessage } from 'react-intl';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. import { debounce } from 'lodash';
  13. const messages = defineMessages({
  14. heading: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' },
  15. });
  16. const mapStateToProps = state => ({
  17. statusIds: state.getIn(['status_lists', 'bookmarks', 'items']),
  18. isLoading: state.getIn(['status_lists', 'bookmarks', 'isLoading'], true),
  19. hasMore: !!state.getIn(['status_lists', 'bookmarks', 'next']),
  20. });
  21. export default @connect(mapStateToProps)
  22. @injectIntl
  23. class Bookmarks extends ImmutablePureComponent {
  24. static propTypes = {
  25. dispatch: PropTypes.func.isRequired,
  26. shouldUpdateScroll: PropTypes.func,
  27. statusIds: ImmutablePropTypes.list.isRequired,
  28. intl: PropTypes.object.isRequired,
  29. columnId: PropTypes.string,
  30. multiColumn: PropTypes.bool,
  31. hasMore: PropTypes.bool,
  32. isLoading: PropTypes.bool,
  33. };
  34. componentWillMount () {
  35. this.props.dispatch(fetchBookmarkedStatuses());
  36. }
  37. handlePin = () => {
  38. const { columnId, dispatch } = this.props;
  39. if (columnId) {
  40. dispatch(removeColumn(columnId));
  41. } else {
  42. dispatch(addColumn('BOOKMARKS', {}));
  43. }
  44. }
  45. handleMove = (dir) => {
  46. const { columnId, dispatch } = this.props;
  47. dispatch(moveColumn(columnId, dir));
  48. }
  49. handleHeaderClick = () => {
  50. this.column.scrollTop();
  51. }
  52. setRef = c => {
  53. this.column = c;
  54. }
  55. handleLoadMore = debounce(() => {
  56. this.props.dispatch(expandBookmarkedStatuses());
  57. }, 300, { leading: true })
  58. render () {
  59. const { intl, shouldUpdateScroll, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
  60. const pinned = !!columnId;
  61. const emptyMessage = <FormattedMessage id='empty_column.bookmarked_statuses' defaultMessage="You don't have any bookmarked toots yet. When you bookmark one, it will show up here." />;
  62. return (
  63. <Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.heading)}>
  64. <ColumnHeader
  65. icon='bookmark'
  66. title={intl.formatMessage(messages.heading)}
  67. onPin={this.handlePin}
  68. onMove={this.handleMove}
  69. onClick={this.handleHeaderClick}
  70. pinned={pinned}
  71. multiColumn={multiColumn}
  72. showBackButton
  73. />
  74. <StatusList
  75. trackScroll={!pinned}
  76. statusIds={statusIds}
  77. scrollKey={`bookmarked_statuses-${columnId}`}
  78. hasMore={hasMore}
  79. isLoading={isLoading}
  80. onLoadMore={this.handleLoadMore}
  81. shouldUpdateScroll={shouldUpdateScroll}
  82. emptyMessage={emptyMessage}
  83. bindToDocument={!multiColumn}
  84. />
  85. </Column>
  86. );
  87. }
  88. }