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.

150 lines
5.3 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import Toggle from 'react-toggle';
  4. import { Motion, spring } from 'react-motion';
  5. import { FormattedMessage } from 'react-intl';
  6. const outerStyle = {
  7. background: '#373b4a',
  8. padding: '15px'
  9. };
  10. const iconStyle = {
  11. fontSize: '16px',
  12. padding: '15px',
  13. position: 'absolute',
  14. right: '0',
  15. top: '-48px',
  16. cursor: 'pointer'
  17. };
  18. const labelStyle = {
  19. display: 'block',
  20. lineHeight: '24px',
  21. verticalAlign: 'middle'
  22. };
  23. const labelSpanStyle = {
  24. display: 'inline-block',
  25. verticalAlign: 'middle',
  26. marginBottom: '14px',
  27. marginLeft: '8px',
  28. color: '#9baec8'
  29. };
  30. const sectionStyle = {
  31. cursor: 'default',
  32. display: 'block',
  33. fontWeight: '500',
  34. color: '#9baec8',
  35. marginBottom: '10px'
  36. };
  37. const rowStyle = {
  38. };
  39. const ColumnSettings = React.createClass({
  40. propTypes: {
  41. settings: ImmutablePropTypes.map.isRequired,
  42. onChange: React.PropTypes.func.isRequired
  43. },
  44. getInitialState () {
  45. return {
  46. collapsed: true
  47. };
  48. },
  49. mixins: [PureRenderMixin],
  50. handleToggleCollapsed () {
  51. this.setState({ collapsed: !this.state.collapsed });
  52. },
  53. handleChange (key, e) {
  54. this.props.onChange(key, e.target.checked);
  55. },
  56. render () {
  57. const { settings } = this.props;
  58. const { collapsed } = this.state;
  59. const alertStr = <FormattedMessage id='notifications.column_settings.alert' defaultMessage='Desktop notifications' />;
  60. const showStr = <FormattedMessage id='notifications.column_settings.show' defaultMessage='Show in column' />;
  61. return (
  62. <div style={{ position: 'relative' }}>
  63. <div style={{...iconStyle, color: collapsed ? '#9baec8' : '#fff', background: collapsed ? '#2f3441' : '#373b4a' }} onClick={this.handleToggleCollapsed}><i className='fa fa-sliders' /></div>
  64. <Motion defaultStyle={{ opacity: 0, height: 0 }} style={{ opacity: spring(collapsed ? 0 : 100), height: spring(collapsed ? 0 : 458) }}>
  65. {({ opacity, height }) =>
  66. <div style={{ overflow: 'hidden', height: `${height}px`, opacity: opacity / 100 }}>
  67. <div style={outerStyle}>
  68. <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.follow' defaultMessage='New followers:' /></span>
  69. <div style={rowStyle}>
  70. <label style={labelStyle}>
  71. <Toggle checked={settings.getIn(['alerts', 'follow'])} onChange={this.handleChange.bind(this, ['alerts', 'follow'])} />
  72. <span style={labelSpanStyle}>{alertStr}</span>
  73. </label>
  74. <label style={labelStyle}>
  75. <Toggle checked={settings.getIn(['shows', 'follow'])} onChange={this.handleChange.bind(this, ['shows', 'follow'])} />
  76. <span style={labelSpanStyle}>{showStr}</span>
  77. </label>
  78. </div>
  79. <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.favourite' defaultMessage='Favourites:' /></span>
  80. <div style={rowStyle}>
  81. <label style={labelStyle}>
  82. <Toggle checked={settings.getIn(['alerts', 'favourite'])} onChange={this.handleChange.bind(this, ['alerts', 'favourite'])} />
  83. <span style={labelSpanStyle}>{alertStr}</span>
  84. </label>
  85. <label style={labelStyle}>
  86. <Toggle checked={settings.getIn(['shows', 'favourite'])} onChange={this.handleChange.bind(this, ['shows', 'favourite'])} />
  87. <span style={labelSpanStyle}>{showStr}</span>
  88. </label>
  89. </div>
  90. <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.mention' defaultMessage='Mentions:' /></span>
  91. <div style={rowStyle}>
  92. <label style={labelStyle}>
  93. <Toggle checked={settings.getIn(['alerts', 'mention'])} onChange={this.handleChange.bind(this, ['alerts', 'mention'])} />
  94. <span style={labelSpanStyle}>{alertStr}</span>
  95. </label>
  96. <label style={labelStyle}>
  97. <Toggle checked={settings.getIn(['shows', 'mention'])} onChange={this.handleChange.bind(this, ['shows', 'mention'])} />
  98. <span style={labelSpanStyle}>{showStr}</span>
  99. </label>
  100. </div>
  101. <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.reblog' defaultMessage='Boosts:' /></span>
  102. <div style={rowStyle}>
  103. <label style={labelStyle}>
  104. <Toggle checked={settings.getIn(['alerts', 'reblog'])} onChange={this.handleChange.bind(this, ['alerts', 'reblog'])} />
  105. <span style={labelSpanStyle}>{alertStr}</span>
  106. </label>
  107. <label style={labelStyle}>
  108. <Toggle checked={settings.getIn(['shows', 'reblog'])} onChange={this.handleChange.bind(this, ['shows', 'reblog'])} />
  109. <span style={labelSpanStyle}>{showStr}</span>
  110. </label>
  111. </div>
  112. </div>
  113. </div>
  114. }
  115. </Motion>
  116. </div>
  117. );
  118. }
  119. });
  120. export default ColumnSettings;