The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

71 satır
2.3 KiB

  1. import { connect } from 'react-redux';
  2. import ComposeForm from '../components/compose_form';
  3. import { createSelector } from 'reselect';
  4. import {
  5. changeCompose,
  6. submitCompose,
  7. clearComposeSuggestions,
  8. fetchComposeSuggestions,
  9. selectComposeSuggestion,
  10. changeComposeSpoilerText,
  11. } from '../../../actions/compose';
  12. const getMentionedUsernames = createSelector(state => state.getIn(['compose', 'text']), text => text.match(/(?:^|[^\/\w])@([a-z0-9_]+@[a-z0-9\.\-]+)/ig));
  13. const getMentionedDomains = createSelector(getMentionedUsernames, mentionedUsernamesWithDomains => {
  14. return mentionedUsernamesWithDomains !== null ? [...new Set(mentionedUsernamesWithDomains.map(item => item.split('@')[2]))] : [];
  15. });
  16. const mapStateToProps = (state, props) => {
  17. const mentionedUsernames = getMentionedUsernames(state);
  18. const mentionedUsernamesWithDomains = getMentionedDomains(state);
  19. return {
  20. text: state.getIn(['compose', 'text']),
  21. suggestion_token: state.getIn(['compose', 'suggestion_token']),
  22. suggestions: state.getIn(['compose', 'suggestions']),
  23. spoiler: state.getIn(['compose', 'spoiler']),
  24. spoiler_text: state.getIn(['compose', 'spoiler_text']),
  25. unlisted: state.getIn(['compose', 'unlisted'], ),
  26. private: state.getIn(['compose', 'private']),
  27. fileDropDate: state.getIn(['compose', 'fileDropDate']),
  28. focusDate: state.getIn(['compose', 'focusDate']),
  29. preselectDate: state.getIn(['compose', 'preselectDate']),
  30. is_submitting: state.getIn(['compose', 'is_submitting']),
  31. is_uploading: state.getIn(['compose', 'is_uploading']),
  32. me: state.getIn(['compose', 'me']),
  33. needsPrivacyWarning: state.getIn(['compose', 'private']) && mentionedUsernames !== null,
  34. mentionedDomains: mentionedUsernamesWithDomains
  35. };
  36. };
  37. const mapDispatchToProps = (dispatch) => ({
  38. onChange (text) {
  39. dispatch(changeCompose(text));
  40. },
  41. onSubmit () {
  42. dispatch(submitCompose());
  43. },
  44. onClearSuggestions () {
  45. dispatch(clearComposeSuggestions());
  46. },
  47. onFetchSuggestions (token) {
  48. dispatch(fetchComposeSuggestions(token));
  49. },
  50. onSuggestionSelected (position, token, accountId) {
  51. dispatch(selectComposeSuggestion(position, token, accountId));
  52. },
  53. onChangeSpoilerText (checked) {
  54. dispatch(changeComposeSpoilerText(checked));
  55. },
  56. });
  57. export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);