2016-09-23 04:58:35 +10:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import {
|
|
|
|
fetchAccount,
|
|
|
|
followAccount,
|
|
|
|
unfollowAccount,
|
2016-10-04 03:49:52 +11:00
|
|
|
blockAccount,
|
|
|
|
unblockAccount,
|
2016-09-23 04:58:35 +10:00
|
|
|
fetchAccountTimeline,
|
|
|
|
expandAccountTimeline
|
|
|
|
} from '../../actions/accounts';
|
2016-10-25 02:11:02 +11:00
|
|
|
import { mentionCompose } from '../../actions/compose';
|
2016-09-23 04:58:35 +10:00
|
|
|
import Header from './components/header';
|
2016-09-24 04:23:26 +10:00
|
|
|
import {
|
2016-10-08 09:01:22 +11:00
|
|
|
getAccountTimeline,
|
2016-10-28 06:59:56 +11:00
|
|
|
makeGetAccount
|
2016-10-08 09:01:22 +11:00
|
|
|
} from '../../selectors';
|
2016-10-07 07:47:35 +11:00
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
2016-09-24 04:23:26 +10:00
|
|
|
import ActionBar from './components/action_bar';
|
2016-10-08 01:00:11 +11:00
|
|
|
import Column from '../ui/components/column';
|
2016-10-20 03:20:19 +11:00
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2017-01-08 21:04:01 +11:00
|
|
|
import { isMobile } from '../../is_mobile'
|
2016-09-19 02:18:46 +10:00
|
|
|
|
2016-10-28 06:59:56 +11:00
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
|
|
|
account: getAccount(state, Number(props.params.accountId)),
|
2016-10-31 01:06:43 +11:00
|
|
|
me: state.getIn(['meta', 'me'])
|
2016-10-28 06:59:56 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
2016-09-16 08:21:51 +10:00
|
|
|
|
|
|
|
const Account = React.createClass({
|
|
|
|
|
2017-01-08 21:04:01 +11:00
|
|
|
contextTypes: {
|
|
|
|
router: React.PropTypes.object
|
|
|
|
},
|
|
|
|
|
2016-09-16 08:21:51 +10:00
|
|
|
propTypes: {
|
|
|
|
params: React.PropTypes.object.isRequired,
|
|
|
|
dispatch: React.PropTypes.func.isRequired,
|
2016-09-19 02:18:46 +10:00
|
|
|
account: ImmutablePropTypes.map,
|
2017-01-21 07:39:41 +11:00
|
|
|
me: React.PropTypes.number.isRequired,
|
|
|
|
children: React.PropTypes.node
|
2016-09-16 08:21:51 +10:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
componentWillMount () {
|
2016-09-19 02:18:46 +10:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
2016-09-16 08:21:51 +10:00
|
|
|
},
|
|
|
|
|
2016-11-06 01:20:05 +11:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2016-09-16 08:21:51 +10:00
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2016-09-19 02:44:52 +10:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
2016-09-16 08:21:51 +10:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-19 02:18:46 +10:00
|
|
|
handleFollow () {
|
2016-10-03 00:14:26 +11:00
|
|
|
if (this.props.account.getIn(['relationship', 'following'])) {
|
|
|
|
this.props.dispatch(unfollowAccount(this.props.account.get('id')));
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(followAccount(this.props.account.get('id')));
|
|
|
|
}
|
2016-09-16 08:21:51 +10:00
|
|
|
},
|
|
|
|
|
2016-10-04 03:49:52 +11:00
|
|
|
handleBlock () {
|
|
|
|
if (this.props.account.getIn(['relationship', 'blocking'])) {
|
|
|
|
this.props.dispatch(unblockAccount(this.props.account.get('id')));
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(blockAccount(this.props.account.get('id')));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-25 02:11:02 +11:00
|
|
|
handleMention () {
|
|
|
|
this.props.dispatch(mentionCompose(this.props.account));
|
2017-01-08 21:04:01 +11:00
|
|
|
if (isMobile(window.innerWidth)) {
|
|
|
|
this.context.router.push('/statuses/new');
|
|
|
|
}
|
2016-10-25 02:11:02 +11:00
|
|
|
},
|
|
|
|
|
2016-09-16 08:21:51 +10:00
|
|
|
render () {
|
2016-10-10 05:18:54 +11:00
|
|
|
const { account, me } = this.props;
|
2016-09-16 08:21:51 +10:00
|
|
|
|
|
|
|
if (account === null) {
|
2016-10-08 01:00:11 +11:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-09-16 08:21:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2016-10-08 01:00:11 +11:00
|
|
|
<Column>
|
2016-10-20 03:20:19 +11:00
|
|
|
<ColumnBackButton />
|
2016-11-24 09:34:12 +11:00
|
|
|
<Header account={account} me={me} onFollow={this.handleFollow} />
|
|
|
|
<ActionBar account={account} me={me} onBlock={this.handleBlock} onMention={this.handleMention} />
|
2016-10-10 05:18:54 +11:00
|
|
|
|
2016-10-17 02:09:00 +11:00
|
|
|
{this.props.children}
|
2016-10-08 01:00:11 +11:00
|
|
|
</Column>
|
2016-09-16 08:21:51 +10:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-10-28 06:59:56 +11:00
|
|
|
export default connect(makeMapStateToProps)(Account);
|