logo

mastofe

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

index.js (2904B)


  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 LoadingIndicator from '../../components/loading_indicator';
  6. import {
  7. fetchAccount,
  8. fetchFollowing,
  9. expandFollowing,
  10. } from '../../actions/accounts';
  11. import { ScrollContainer } from 'react-router-scroll-4';
  12. import AccountContainer from '../../containers/account_container';
  13. import Column from '../ui/components/column';
  14. import HeaderContainer from '../account_timeline/containers/header_container';
  15. import LoadMore from '../../components/load_more';
  16. import ColumnBackButton from '../../components/column_back_button';
  17. import ImmutablePureComponent from 'react-immutable-pure-component';
  18. const mapStateToProps = (state, props) => ({
  19. accountIds: state.getIn(['user_lists', 'following', props.params.accountId, 'items']),
  20. hasMore: !!state.getIn(['user_lists', 'following', props.params.accountId, 'next']),
  21. });
  22. @connect(mapStateToProps)
  23. export default class Following extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. accountIds: ImmutablePropTypes.list,
  28. hasMore: PropTypes.bool,
  29. };
  30. componentWillMount () {
  31. this.props.dispatch(fetchAccount(this.props.params.accountId));
  32. this.props.dispatch(fetchFollowing(this.props.params.accountId));
  33. }
  34. componentWillReceiveProps (nextProps) {
  35. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  36. this.props.dispatch(fetchAccount(nextProps.params.accountId));
  37. this.props.dispatch(fetchFollowing(nextProps.params.accountId));
  38. }
  39. }
  40. handleScroll = (e) => {
  41. const { scrollTop, scrollHeight, clientHeight } = e.target;
  42. if (scrollTop === scrollHeight - clientHeight && this.props.hasMore) {
  43. this.props.dispatch(expandFollowing(this.props.params.accountId));
  44. }
  45. }
  46. handleLoadMore = (e) => {
  47. e.preventDefault();
  48. this.props.dispatch(expandFollowing(this.props.params.accountId));
  49. }
  50. render () {
  51. const { accountIds, hasMore } = this.props;
  52. let loadMore = null;
  53. if (!accountIds) {
  54. return (
  55. <Column>
  56. <LoadingIndicator />
  57. </Column>
  58. );
  59. }
  60. if (hasMore) {
  61. loadMore = <LoadMore onClick={this.handleLoadMore} />;
  62. }
  63. return (
  64. <Column>
  65. <ColumnBackButton />
  66. <ScrollContainer scrollKey='following'>
  67. <div className='scrollable' onScroll={this.handleScroll}>
  68. <div className='following'>
  69. <HeaderContainer accountId={this.props.params.accountId} hideTabs />
  70. {accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
  71. {loadMore}
  72. </div>
  73. </div>
  74. </ScrollContainer>
  75. </Column>
  76. );
  77. }
  78. }