1
0

index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { debounce } from 'lodash';
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import { Helmet } from 'react-helmet';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. import { connect } from 'react-redux';
  9. import { fetchBookmarkedStatuses, expandBookmarkedStatuses } from 'mastodon/actions/bookmarks';
  10. import { addColumn, removeColumn, moveColumn } from 'mastodon/actions/columns';
  11. import ColumnHeader from 'mastodon/components/column_header';
  12. import StatusList from 'mastodon/components/status_list';
  13. import Column from 'mastodon/features/ui/components/column';
  14. const messages = defineMessages({
  15. heading: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' },
  16. });
  17. const mapStateToProps = state => ({
  18. statusIds: state.getIn(['status_lists', 'bookmarks', 'items']),
  19. isLoading: state.getIn(['status_lists', 'bookmarks', 'isLoading'], true),
  20. hasMore: !!state.getIn(['status_lists', 'bookmarks', 'next']),
  21. });
  22. export default @connect(mapStateToProps)
  23. @injectIntl
  24. class Bookmarks extends ImmutablePureComponent {
  25. static propTypes = {
  26. dispatch: PropTypes.func.isRequired,
  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, 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 posts 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. emptyMessage={emptyMessage}
  82. bindToDocument={!multiColumn}
  83. />
  84. <Helmet>
  85. <title>{intl.formatMessage(messages.heading)}</title>
  86. <meta name='robots' content='noindex' />
  87. </Helmet>
  88. </Column>
  89. );
  90. }
  91. }