2016-10-31 02:13:05 +09:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ComposeForm from '../components/compose_form';
|
2017-03-01 19:56:15 +09:00
|
|
|
import { uploadCompose } from '../../../actions/compose';
|
2017-02-26 09:23:44 +09:00
|
|
|
import { createSelector } from 'reselect';
|
2016-10-31 02:13:05 +09:00
|
|
|
import {
|
|
|
|
changeCompose,
|
|
|
|
submitCompose,
|
|
|
|
clearComposeSuggestions,
|
2016-11-12 22:33:21 +09:00
|
|
|
fetchComposeSuggestions,
|
2016-11-24 02:53:23 +09:00
|
|
|
selectComposeSuggestion,
|
2017-01-13 13:54:26 +09:00
|
|
|
changeComposeSpoilerText,
|
2017-03-02 08:57:55 +09:00
|
|
|
insertEmojiCompose
|
2016-10-31 02:13:05 +09:00
|
|
|
} from '../../../actions/compose';
|
2016-09-05 23:56:43 +09:00
|
|
|
|
2017-02-26 09:23:44 +09:00
|
|
|
const getMentionedUsernames = createSelector(state => state.getIn(['compose', 'text']), text => text.match(/(?:^|[^\/\w])@([a-z0-9_]+@[a-z0-9\.\-]+)/ig));
|
|
|
|
|
|
|
|
const getMentionedDomains = createSelector(getMentionedUsernames, mentionedUsernamesWithDomains => {
|
|
|
|
return mentionedUsernamesWithDomains !== null ? [...new Set(mentionedUsernamesWithDomains.map(item => item.split('@')[2]))] : [];
|
|
|
|
});
|
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
const mapStateToProps = (state, props) => {
|
2017-02-26 09:23:44 +09:00
|
|
|
const mentionedUsernames = getMentionedUsernames(state);
|
|
|
|
const mentionedUsernamesWithDomains = getMentionedDomains(state);
|
2016-10-25 00:11:02 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
return {
|
|
|
|
text: state.getIn(['compose', 'text']),
|
|
|
|
suggestion_token: state.getIn(['compose', 'suggestion_token']),
|
|
|
|
suggestions: state.getIn(['compose', 'suggestions']),
|
|
|
|
spoiler: state.getIn(['compose', 'spoiler']),
|
|
|
|
spoiler_text: state.getIn(['compose', 'spoiler_text']),
|
|
|
|
unlisted: state.getIn(['compose', 'unlisted'], ),
|
|
|
|
private: state.getIn(['compose', 'private']),
|
|
|
|
focusDate: state.getIn(['compose', 'focusDate']),
|
|
|
|
preselectDate: state.getIn(['compose', 'preselectDate']),
|
|
|
|
is_submitting: state.getIn(['compose', 'is_submitting']),
|
|
|
|
is_uploading: state.getIn(['compose', 'is_uploading']),
|
|
|
|
me: state.getIn(['compose', 'me']),
|
2017-02-26 09:23:44 +09:00
|
|
|
needsPrivacyWarning: state.getIn(['compose', 'private']) && mentionedUsernames !== null,
|
|
|
|
mentionedDomains: mentionedUsernamesWithDomains
|
2016-08-31 23:15:12 +09:00
|
|
|
};
|
2016-08-26 02:52:55 +09:00
|
|
|
};
|
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2016-08-31 23:15:12 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onChange (text) {
|
|
|
|
dispatch(changeCompose(text));
|
|
|
|
},
|
2016-09-01 05:58:10 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onSubmit () {
|
|
|
|
dispatch(submitCompose());
|
|
|
|
},
|
2016-10-31 02:13:05 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onClearSuggestions () {
|
|
|
|
dispatch(clearComposeSuggestions());
|
|
|
|
},
|
2016-10-31 02:13:05 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onFetchSuggestions (token) {
|
|
|
|
dispatch(fetchComposeSuggestions(token));
|
|
|
|
},
|
2016-11-12 22:33:21 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onSuggestionSelected (position, token, accountId) {
|
|
|
|
dispatch(selectComposeSuggestion(position, token, accountId));
|
|
|
|
},
|
2016-11-24 02:53:23 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
onChangeSpoilerText (checked) {
|
|
|
|
dispatch(changeComposeSpoilerText(checked));
|
|
|
|
},
|
2017-01-13 13:54:26 +09:00
|
|
|
|
2017-03-01 19:56:15 +09:00
|
|
|
onPaste (files) {
|
|
|
|
dispatch(uploadCompose(files));
|
|
|
|
},
|
|
|
|
|
2017-03-02 08:57:55 +09:00
|
|
|
onPickEmoji (position, data) {
|
|
|
|
dispatch(insertEmojiCompose(position, data));
|
|
|
|
},
|
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
});
|
2016-08-26 02:52:55 +09:00
|
|
|
|
2017-02-22 23:43:07 +09:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);
|