logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status_list.js (2895B)


  1. import { debounce } from 'lodash';
  2. import React from 'react';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  5. import StatusContainer from '../containers/status_container';
  6. import ImmutablePureComponent from 'react-immutable-pure-component';
  7. import LoadGap from './load_gap';
  8. import ScrollableList from './scrollable_list';
  9. import { FormattedMessage } from 'react-intl';
  10. export default class StatusList extends ImmutablePureComponent {
  11. static propTypes = {
  12. scrollKey: PropTypes.string.isRequired,
  13. statusIds: ImmutablePropTypes.list.isRequired,
  14. onLoadMore: PropTypes.func,
  15. onScrollToTop: PropTypes.func,
  16. onScroll: PropTypes.func,
  17. trackScroll: PropTypes.bool,
  18. shouldUpdateScroll: PropTypes.func,
  19. isLoading: PropTypes.bool,
  20. isPartial: PropTypes.bool,
  21. hasMore: PropTypes.bool,
  22. prepend: PropTypes.node,
  23. emptyMessage: PropTypes.node,
  24. };
  25. static defaultProps = {
  26. trackScroll: true,
  27. };
  28. handleMoveUp = id => {
  29. const elementIndex = this.props.statusIds.indexOf(id) - 1;
  30. this._selectChild(elementIndex);
  31. }
  32. handleMoveDown = id => {
  33. const elementIndex = this.props.statusIds.indexOf(id) + 1;
  34. this._selectChild(elementIndex);
  35. }
  36. handleLoadOlder = debounce(() => {
  37. this.props.onLoadMore(this.props.statusIds.last());
  38. }, 300, { leading: true })
  39. _selectChild (index) {
  40. const element = this.node.node.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
  41. if (element) {
  42. element.focus();
  43. }
  44. }
  45. setRef = c => {
  46. this.node = c;
  47. }
  48. render () {
  49. const { statusIds, onLoadMore, ...other } = this.props;
  50. const { isLoading, isPartial } = other;
  51. if (isPartial) {
  52. return (
  53. <div className='regeneration-indicator'>
  54. <div>
  55. <div className='regeneration-indicator__label'>
  56. <FormattedMessage id='regeneration_indicator.label' tagName='strong' defaultMessage='Loading&hellip;' />
  57. <FormattedMessage id='regeneration_indicator.sublabel' defaultMessage='Your home feed is being prepared!' />
  58. </div>
  59. </div>
  60. </div>
  61. );
  62. }
  63. let scrollableContent = (isLoading || statusIds.size > 0) ? (
  64. statusIds.map((statusId, index) => statusId === null ? (
  65. <LoadGap
  66. key={'gap:' + statusIds.get(index + 1)}
  67. disabled={isLoading}
  68. maxId={index > 0 ? statusIds.get(index - 1) : null}
  69. onClick={onLoadMore}
  70. />
  71. ) : (
  72. <StatusContainer
  73. key={statusId}
  74. id={statusId}
  75. onMoveUp={this.handleMoveUp}
  76. onMoveDown={this.handleMoveDown}
  77. />
  78. ))
  79. ) : null;
  80. return (
  81. <ScrollableList {...other} onLoadMore={onLoadMore && this.handleLoadOlder} ref={this.setRef}>
  82. {scrollableContent}
  83. </ScrollableList>
  84. );
  85. }
  86. }