logo

mastofe

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

index.js (2813B)


  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  5. import { fetchAccount } from '../../actions/accounts';
  6. import { expandAccountTimeline } from '../../actions/timelines';
  7. import StatusList from '../../components/status_list';
  8. import LoadingIndicator from '../../components/loading_indicator';
  9. import Column from '../ui/components/column';
  10. import HeaderContainer from './containers/header_container';
  11. import ColumnBackButton from '../../components/column_back_button';
  12. import { List as ImmutableList } from 'immutable';
  13. import ImmutablePureComponent from 'react-immutable-pure-component';
  14. const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
  15. const path = withReplies ? `${accountId}:with_replies` : accountId;
  16. return {
  17. statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
  18. isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
  19. hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
  20. };
  21. };
  22. @connect(mapStateToProps)
  23. export default class AccountTimeline extends ImmutablePureComponent {
  24. static propTypes = {
  25. params: PropTypes.object.isRequired,
  26. dispatch: PropTypes.func.isRequired,
  27. statusIds: ImmutablePropTypes.list,
  28. isLoading: PropTypes.bool,
  29. hasMore: PropTypes.bool,
  30. withReplies: PropTypes.bool,
  31. };
  32. componentWillMount () {
  33. const { params: { accountId }, withReplies } = this.props;
  34. this.props.dispatch(fetchAccount(accountId));
  35. this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
  36. }
  37. componentWillReceiveProps (nextProps) {
  38. if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
  39. this.props.dispatch(fetchAccount(nextProps.params.accountId));
  40. this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
  41. }
  42. }
  43. handleLoadMore = maxId => {
  44. this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies }));
  45. }
  46. render () {
  47. const { statusIds, isLoading, hasMore } = this.props;
  48. if (!statusIds && isLoading) {
  49. return (
  50. <Column>
  51. <LoadingIndicator />
  52. </Column>
  53. );
  54. }
  55. return (
  56. <Column>
  57. <ColumnBackButton />
  58. <StatusList
  59. prepend={<HeaderContainer accountId={this.props.params.accountId} />}
  60. scrollKey='account_timeline'
  61. statusIds={statusIds}
  62. isLoading={isLoading}
  63. hasMore={hasMore}
  64. onLoadMore={this.handleLoadMore}
  65. />
  66. </Column>
  67. );
  68. }
  69. }