The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

110 linhas
3.0 KiB

  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import {
  5. fetchAccount,
  6. followAccount,
  7. unfollowAccount,
  8. blockAccount,
  9. unblockAccount,
  10. fetchAccountTimeline,
  11. expandAccountTimeline
  12. } from '../../actions/accounts';
  13. import { mentionCompose } from '../../actions/compose';
  14. import Header from './components/header';
  15. import {
  16. getAccountTimeline,
  17. makeGetAccount
  18. } from '../../selectors';
  19. import LoadingIndicator from '../../components/loading_indicator';
  20. import ActionBar from './components/action_bar';
  21. import Column from '../ui/components/column';
  22. import ColumnBackButton from '../../components/column_back_button';
  23. import { isMobile } from '../../is_mobile'
  24. const makeMapStateToProps = () => {
  25. const getAccount = makeGetAccount();
  26. const mapStateToProps = (state, props) => ({
  27. account: getAccount(state, Number(props.params.accountId)),
  28. me: state.getIn(['meta', 'me'])
  29. });
  30. return mapStateToProps;
  31. };
  32. const Account = React.createClass({
  33. contextTypes: {
  34. router: React.PropTypes.object
  35. },
  36. propTypes: {
  37. params: React.PropTypes.object.isRequired,
  38. dispatch: React.PropTypes.func.isRequired,
  39. account: ImmutablePropTypes.map,
  40. me: React.PropTypes.number.isRequired,
  41. children: React.PropTypes.node
  42. },
  43. mixins: [PureRenderMixin],
  44. componentWillMount () {
  45. this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
  46. },
  47. componentWillReceiveProps (nextProps) {
  48. if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
  49. this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
  50. }
  51. },
  52. handleFollow () {
  53. if (this.props.account.getIn(['relationship', 'following'])) {
  54. this.props.dispatch(unfollowAccount(this.props.account.get('id')));
  55. } else {
  56. this.props.dispatch(followAccount(this.props.account.get('id')));
  57. }
  58. },
  59. handleBlock () {
  60. if (this.props.account.getIn(['relationship', 'blocking'])) {
  61. this.props.dispatch(unblockAccount(this.props.account.get('id')));
  62. } else {
  63. this.props.dispatch(blockAccount(this.props.account.get('id')));
  64. }
  65. },
  66. handleMention () {
  67. this.props.dispatch(mentionCompose(this.props.account));
  68. if (isMobile(window.innerWidth)) {
  69. this.context.router.push('/statuses/new');
  70. }
  71. },
  72. render () {
  73. const { account, me } = this.props;
  74. if (account === null) {
  75. return (
  76. <Column>
  77. <LoadingIndicator />
  78. </Column>
  79. );
  80. }
  81. return (
  82. <Column>
  83. <ColumnBackButton />
  84. <Header account={account} me={me} onFollow={this.handleFollow} />
  85. <ActionBar account={account} me={me} onBlock={this.handleBlock} onMention={this.handleMention} />
  86. {this.props.children}
  87. </Column>
  88. );
  89. }
  90. });
  91. export default connect(makeMapStateToProps)(Account);