You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2 KiB

  1. import CharacterCounter from './character_counter';
  2. import Button from '../../../components/button';
  3. import PureRenderMixin from 'react-addons-pure-render-mixin';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import ReplyIndicator from './reply_indicator';
  6. import UploadButton from './upload_button';
  7. const ComposeForm = React.createClass({
  8. propTypes: {
  9. text: React.PropTypes.string.isRequired,
  10. is_submitting: React.PropTypes.bool,
  11. is_uploading: React.PropTypes.bool,
  12. in_reply_to: ImmutablePropTypes.map,
  13. onChange: React.PropTypes.func.isRequired,
  14. onSubmit: React.PropTypes.func.isRequired,
  15. onCancelReply: React.PropTypes.func.isRequired
  16. },
  17. mixins: [PureRenderMixin],
  18. handleChange (e) {
  19. this.props.onChange(e.target.value);
  20. },
  21. handleKeyUp (e) {
  22. if (e.keyCode === 13 && e.ctrlKey) {
  23. this.props.onSubmit();
  24. }
  25. },
  26. handleSubmit () {
  27. this.props.onSubmit();
  28. },
  29. componentDidUpdate (prevProps) {
  30. if (prevProps.text !== this.props.text || prevProps.in_reply_to !== this.props.in_reply_to) {
  31. this.refs.textarea.focus();
  32. }
  33. },
  34. render () {
  35. let replyArea = '';
  36. const disabled = this.props.is_submitting || this.props.is_uploading;
  37. if (this.props.in_reply_to) {
  38. replyArea = <ReplyIndicator status={this.props.in_reply_to} onCancel={this.props.onCancelReply} />;
  39. }
  40. return (
  41. <div style={{ padding: '10px' }}>
  42. {replyArea}
  43. <textarea ref='textarea' disabled={disabled} placeholder='What is on your mind?' value={this.props.text} onKeyUp={this.handleKeyUp} onChange={this.handleChange} className='compose-form__textarea' style={{ display: 'block', boxSizing: 'border-box', width: '100%', height: '100px', resize: 'none', border: 'none', color: '#282c37', padding: '10px', fontFamily: 'Roboto', fontSize: '14px', margin: '0' }} />
  44. <div style={{ marginTop: '10px', overflow: 'hidden' }}>
  45. <div style={{ float: 'right' }}><Button text='Publish' onClick={this.handleSubmit} disabled={disabled} /></div>
  46. <div style={{ float: 'right', marginRight: '16px', lineHeight: '36px' }}><CharacterCounter max={500} text={this.props.text} /></div>
  47. </div>
  48. </div>
  49. );
  50. }
  51. });
  52. export default ComposeForm;