The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

73 lines
1.8 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import StatusContainer from '../containers/status_container';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import ScrollableList from './scrollable_list';
  7. export default class StatusList extends ImmutablePureComponent {
  8. static propTypes = {
  9. scrollKey: PropTypes.string.isRequired,
  10. statusIds: ImmutablePropTypes.list.isRequired,
  11. onScrollToBottom: PropTypes.func,
  12. onScrollToTop: PropTypes.func,
  13. onScroll: PropTypes.func,
  14. trackScroll: PropTypes.bool,
  15. shouldUpdateScroll: PropTypes.func,
  16. isLoading: PropTypes.bool,
  17. hasMore: PropTypes.bool,
  18. prepend: PropTypes.node,
  19. emptyMessage: PropTypes.node,
  20. };
  21. static defaultProps = {
  22. trackScroll: true,
  23. };
  24. handleMoveUp = id => {
  25. const elementIndex = this.props.statusIds.indexOf(id) - 1;
  26. this._selectChild(elementIndex);
  27. }
  28. handleMoveDown = id => {
  29. const elementIndex = this.props.statusIds.indexOf(id) + 1;
  30. this._selectChild(elementIndex);
  31. }
  32. _selectChild (index) {
  33. const element = this.node.node.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
  34. if (element) {
  35. element.focus();
  36. }
  37. }
  38. setRef = c => {
  39. this.node = c;
  40. }
  41. render () {
  42. const { statusIds, ...other } = this.props;
  43. const { isLoading } = other;
  44. const scrollableContent = (isLoading || statusIds.size > 0) ? (
  45. statusIds.map((statusId) => (
  46. <StatusContainer
  47. key={statusId}
  48. id={statusId}
  49. onMoveUp={this.handleMoveUp}
  50. onMoveDown={this.handleMoveDown}
  51. />
  52. ))
  53. ) : null;
  54. return (
  55. <ScrollableList {...other} ref={this.setRef}>
  56. {scrollableContent}
  57. </ScrollableList>
  58. );
  59. }
  60. }