about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/notifications/components/column_settings.jsx
blob: b4035c20d5af8861f364703f5d78ba45c9ccf617 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Toggle from 'react-toggle';
import { Motion, spring } from 'react-motion';
import { FormattedMessage } from 'react-intl';

const outerStyle = {
  background: '#373b4a',
  padding: '15px'
};

const iconStyle = {
  fontSize: '16px',
  padding: '15px',
  position: 'absolute',
  right: '0',
  top: '-48px',
  cursor: 'pointer'
};

const labelStyle = {
  display: 'block',
  lineHeight: '24px',
  verticalAlign: 'middle'
};

const labelSpanStyle = {
  display: 'inline-block',
  verticalAlign: 'middle',
  marginBottom: '14px',
  marginLeft: '8px',
  color: '#9baec8'
};

const sectionStyle = {
  cursor: 'default',
  display: 'block',
  fontWeight: '500',
  color: '#9baec8',
  marginBottom: '10px'
};

const rowStyle = {

};

const ColumnSettings = React.createClass({

  propTypes: {
    settings: ImmutablePropTypes.map.isRequired,
    onChange: React.PropTypes.func.isRequired
  },

  getInitialState () {
    return {
      collapsed: true
    };
  },

  mixins: [PureRenderMixin],

  handleToggleCollapsed () {
    this.setState({ collapsed: !this.state.collapsed });
  },

  handleChange (key, e) {
    this.props.onChange(key, e.target.checked);
  },

  render () {
    const { settings }  = this.props;
    const { collapsed } = this.state;

    const alertStr = <FormattedMessage id='notifications.column_settings.alert' defaultMessage='Desktop notifications' />;
    const showStr  = <FormattedMessage id='notifications.column_settings.show' defaultMessage='Show in column' />;

    return (
      <div style={{ position: 'relative' }}>
        <div style={{...iconStyle, color: collapsed ? '#9baec8' : '#fff', background: collapsed ? '#2f3441' : '#373b4a' }} onClick={this.handleToggleCollapsed}><i className='fa fa-sliders' /></div>

        <Motion defaultStyle={{ opacity: 0, height: 0 }} style={{ opacity: spring(collapsed ? 0 : 100), height: spring(collapsed ? 0 : 458) }}>
          {({ opacity, height }) =>
            <div style={{ overflow: 'hidden', height: `${height}px`, opacity: opacity / 100 }}>
              <div style={outerStyle}>
                <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.follow' defaultMessage='New followers:' /></span>

                <div style={rowStyle}>
                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['alerts', 'follow'])} onChange={this.handleChange.bind(this, ['alerts', 'follow'])} />
                    <span style={labelSpanStyle}>{alertStr}</span>
                  </label>

                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['shows', 'follow'])} onChange={this.handleChange.bind(this, ['shows', 'follow'])} />
                    <span style={labelSpanStyle}>{showStr}</span>
                  </label>
                </div>

                <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.favourite' defaultMessage='Favourites:' /></span>

                <div style={rowStyle}>
                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['alerts', 'favourite'])} onChange={this.handleChange.bind(this, ['alerts', 'favourite'])} />
                    <span style={labelSpanStyle}>{alertStr}</span>
                  </label>

                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['shows', 'favourite'])} onChange={this.handleChange.bind(this, ['shows', 'favourite'])} />
                    <span style={labelSpanStyle}>{showStr}</span>
                  </label>
                </div>

                <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.mention' defaultMessage='Mentions:' /></span>

                <div style={rowStyle}>
                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['alerts', 'mention'])} onChange={this.handleChange.bind(this, ['alerts', 'mention'])} />
                    <span style={labelSpanStyle}>{alertStr}</span>
                  </label>

                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['shows', 'mention'])} onChange={this.handleChange.bind(this, ['shows', 'mention'])} />
                    <span style={labelSpanStyle}>{showStr}</span>
                  </label>
                </div>

                <span style={sectionStyle}><FormattedMessage id='notifications.column_settings.reblog' defaultMessage='Boosts:' /></span>

                <div style={rowStyle}>
                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['alerts', 'reblog'])} onChange={this.handleChange.bind(this, ['alerts', 'reblog'])} />
                    <span style={labelSpanStyle}>{alertStr}</span>
                  </label>

                  <label style={labelStyle}>
                    <Toggle checked={settings.getIn(['shows', 'reblog'])} onChange={this.handleChange.bind(this, ['shows', 'reblog'])} />
                    <span style={labelSpanStyle}>{showStr}</span>
                  </label>
                </div>
              </div>
            </div>
          }
        </Motion>
      </div>
    );
  }

});

export default ColumnSettings;