about summary refs log tree commit diff
path: root/app/javascript/themes/glitch/features/compose/components/advanced_options.js
blob: 045bad2e5d50f4af0750bf1907affd95d70a214e (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
//  Package imports.
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl, defineMessages } from 'react-intl';

//  Our imports.
import ComposeAdvancedOptionsToggle from './advanced_options_toggle';
import ComposeDropdown from './dropdown';

const messages = defineMessages({
  local_only_short            :
    { id: 'advanced-options.local-only.short', defaultMessage: 'Local-only' },
  local_only_long             :
    { id: 'advanced-options.local-only.long', defaultMessage: 'Do not post to other instances' },
  advanced_options_icon_title :
    { id: 'advanced_options.icon_title', defaultMessage: 'Advanced options' },
});

@injectIntl
export default class ComposeAdvancedOptions extends React.PureComponent {

  static propTypes = {
    values   : ImmutablePropTypes.contains({
      do_not_federate : PropTypes.bool.isRequired,
    }).isRequired,
    onChange : PropTypes.func.isRequired,
    intl     : PropTypes.object.isRequired,
  };

  render () {
    const { intl, values } = this.props;
    const options = [
      { icon: 'wifi', shortText: messages.local_only_short, longText: messages.local_only_long, name: 'do_not_federate' },
    ];
    const anyEnabled = values.some((enabled) => enabled);

    const optionElems = options.map((option) => {
      return (
        <ComposeAdvancedOptionsToggle
          onChange={this.props.onChange}
          active={values.get(option.name)}
          key={option.name}
          name={option.name}
          shortText={intl.formatMessage(option.shortText)}
          longText={intl.formatMessage(option.longText)}
        />
      );
    });

    return (
      <ComposeDropdown
        title={intl.formatMessage(messages.advanced_options_icon_title)}
        icon='home'
        highlight={anyEnabled}
      >
        {optionElems}
      </ComposeDropdown>
    );
  }

}