2016-09-23 03:58:35 +09: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 01:49:52 +09:00
|
|
|
blockAccount,
|
|
|
|
unblockAccount,
|
2016-09-23 03:58:35 +09:00
|
|
|
fetchAccountTimeline,
|
|
|
|
expandAccountTimeline
|
|
|
|
} from '../../actions/accounts';
|
2016-09-30 07:00:45 +09:00
|
|
|
import { deleteStatus } from '../../actions/statuses';
|
2016-09-23 03:58:35 +09:00
|
|
|
import { replyCompose } from '../../actions/compose';
|
2016-10-02 22:14:26 +09:00
|
|
|
import {
|
|
|
|
favourite,
|
|
|
|
reblog,
|
|
|
|
unreblog,
|
|
|
|
unfavourite
|
|
|
|
} from '../../actions/interactions';
|
2016-09-23 03:58:35 +09:00
|
|
|
import Header from './components/header';
|
2016-09-24 03:23:26 +09:00
|
|
|
import {
|
2016-10-08 07:01:22 +09:00
|
|
|
getAccountTimeline,
|
|
|
|
getAccount
|
|
|
|
} from '../../selectors';
|
2016-09-23 03:58:35 +09:00
|
|
|
import StatusList from '../../components/status_list';
|
2016-10-07 05:47:35 +09:00
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
2016-09-23 03:58:35 +09:00
|
|
|
import Immutable from 'immutable';
|
2016-09-24 03:23:26 +09:00
|
|
|
import ActionBar from './components/action_bar';
|
2016-10-07 23:00:11 +09:00
|
|
|
import Column from '../ui/components/column';
|
2016-09-19 01:18:46 +09:00
|
|
|
|
2016-09-16 07:21:51 +09:00
|
|
|
const mapStateToProps = (state, props) => ({
|
2016-10-08 07:01:22 +09:00
|
|
|
account: getAccount(state, Number(props.params.accountId)),
|
|
|
|
statuses: getAccountTimeline(state, Number(props.params.accountId)),
|
2016-09-24 03:23:26 +09:00
|
|
|
me: state.getIn(['timelines', 'me'])
|
2016-09-16 07:21:51 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const Account = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
params: React.PropTypes.object.isRequired,
|
|
|
|
dispatch: React.PropTypes.func.isRequired,
|
2016-09-19 01:18:46 +09:00
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
statuses: ImmutablePropTypes.list
|
2016-09-16 07:21:51 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
componentWillMount () {
|
2016-09-19 01:18:46 +09:00
|
|
|
this.props.dispatch(fetchAccount(Number(this.props.params.accountId)));
|
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(this.props.params.accountId)));
|
2016-09-16 07:21:51 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
|
2016-09-19 01:44:52 +09:00
|
|
|
this.props.dispatch(fetchAccount(Number(nextProps.params.accountId)));
|
|
|
|
this.props.dispatch(fetchAccountTimeline(Number(nextProps.params.accountId)));
|
2016-09-16 07:21:51 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-19 01:18:46 +09:00
|
|
|
handleFollow () {
|
2016-10-02 22:14:26 +09: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 07:21:51 +09:00
|
|
|
},
|
|
|
|
|
2016-10-04 01:49:52 +09: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-09-19 01:18:46 +09:00
|
|
|
handleReply (status) {
|
|
|
|
this.props.dispatch(replyCompose(status));
|
|
|
|
},
|
|
|
|
|
|
|
|
handleReblog (status) {
|
2016-10-02 22:14:26 +09:00
|
|
|
if (status.get('reblogged')) {
|
|
|
|
this.props.dispatch(unreblog(status));
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(reblog(status));
|
|
|
|
}
|
2016-09-19 01:18:46 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
handleFavourite (status) {
|
2016-10-02 22:14:26 +09:00
|
|
|
if (status.get('favourited')) {
|
|
|
|
this.props.dispatch(unfavourite(status));
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(favourite(status));
|
|
|
|
}
|
2016-09-19 01:18:46 +09:00
|
|
|
},
|
|
|
|
|
2016-09-30 07:00:45 +09:00
|
|
|
handleDelete (status) {
|
|
|
|
this.props.dispatch(deleteStatus(status.get('id')));
|
|
|
|
},
|
|
|
|
|
2016-09-23 03:58:35 +09:00
|
|
|
handleScrollToBottom () {
|
|
|
|
this.props.dispatch(expandAccountTimeline(this.props.account.get('id')));
|
|
|
|
},
|
|
|
|
|
2016-09-16 07:21:51 +09:00
|
|
|
render () {
|
2016-09-24 03:23:26 +09:00
|
|
|
const { account, statuses, me } = this.props;
|
2016-09-16 07:21:51 +09:00
|
|
|
|
|
|
|
if (account === null) {
|
2016-10-07 23:00:11 +09:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-09-16 07:21:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2016-10-07 23:00:11 +09:00
|
|
|
<Column>
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column', 'flex': '0 0 auto', height: '100%' }}>
|
|
|
|
<Header account={account} />
|
|
|
|
<ActionBar account={account} me={me} onFollow={this.handleFollow} onBlock={this.handleBlock} />
|
|
|
|
<StatusList statuses={statuses} me={me} onScrollToBottom={this.handleScrollToBottom} onReply={this.handleReply} onReblog={this.handleReblog} onFavourite={this.handleFavourite} onDelete={this.handleDelete} />
|
|
|
|
</div>
|
|
|
|
</Column>
|
2016-09-16 07:21:51 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Account);
|