2016-08-31 22:58:10 +02:00
|
|
|
import { connect } from 'react-redux';
|
2016-09-03 14:01:10 +02:00
|
|
|
import ComposeForm from '../components/compose_form';
|
2016-08-31 22:58:10 +02:00
|
|
|
import { changeCompose, submitCompose, cancelReplyCompose } from '../actions/compose';
|
2016-08-25 19:52:55 +02:00
|
|
|
|
2016-09-05 16:56:43 +02:00
|
|
|
function selectStatus(state) {
|
|
|
|
let statusId = state.getIn(['compose', 'in_reply_to'], null);
|
|
|
|
|
|
|
|
if (statusId === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let status = state.getIn(['timelines', 'statuses', statusId]);
|
|
|
|
status = status.set('account', state.getIn(['timelines', 'accounts', status.get('account')]));
|
|
|
|
|
|
|
|
return status;
|
|
|
|
};
|
|
|
|
|
2016-08-25 19:52:55 +02:00
|
|
|
const mapStateToProps = function (state, props) {
|
2016-08-31 16:15:12 +02:00
|
|
|
return {
|
|
|
|
text: state.getIn(['compose', 'text']),
|
2016-08-31 22:58:10 +02:00
|
|
|
is_submitting: state.getIn(['compose', 'is_submitting']),
|
2016-09-05 16:56:43 +02:00
|
|
|
in_reply_to: selectStatus(state)
|
2016-08-31 16:15:12 +02:00
|
|
|
};
|
2016-08-25 19:52:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = function (dispatch) {
|
|
|
|
return {
|
2016-08-31 16:15:12 +02:00
|
|
|
onChange: function (text) {
|
|
|
|
dispatch(changeCompose(text));
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit: function () {
|
|
|
|
dispatch(submitCompose());
|
2016-08-31 22:58:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onCancelReply: function () {
|
|
|
|
dispatch(cancelReplyCompose());
|
2016-08-25 19:52:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-03 14:01:10 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);
|