about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/compose/components/privacy_dropdown.js
blob: 02cf7228914d8b2526f82c1f89a98f6c2f90f9c6 (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
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { defineMessages, injectIntl } from 'react-intl';
import Dropdown from './dropdown';

const messages = defineMessages({
  public_short: { id: 'privacy.public.short', defaultMessage: 'Public' },
  public_long: { id: 'privacy.public.long', defaultMessage: 'Visible for all' },
  unlisted_short: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
  unlisted_long: { id: 'privacy.unlisted.long', defaultMessage: 'Visible for all, but opted-out of discovery features' },
  private_short: { id: 'privacy.private.short', defaultMessage: 'Followers only' },
  private_long: { id: 'privacy.private.long', defaultMessage: 'Visible for followers only' },
  direct_short: { id: 'privacy.direct.short', defaultMessage: 'Only people I mention' },
  direct_long: { id: 'privacy.direct.long', defaultMessage: 'Visible for mentioned users only' },
  change_privacy: { id: 'privacy.change', defaultMessage: 'Adjust status privacy' },
});

export default @injectIntl
class PrivacyDropdown extends React.PureComponent {

  static propTypes = {
    isUserTouching: PropTypes.func,
    onModalOpen: PropTypes.func,
    onModalClose: PropTypes.func,
    value: PropTypes.string.isRequired,
    onChange: PropTypes.func.isRequired,
    noDirect: PropTypes.bool,
    container: PropTypes.func,
    disabled: PropTypes.bool,
    intl: PropTypes.object.isRequired,
  };

  render () {
    const { value, onChange, onModalOpen, onModalClose, disabled, noDirect, container, isUserTouching, intl: { formatMessage } } = this.props;

    //  We predefine our privacy items so that we can easily pick the
    //  dropdown icon later.
    const privacyItems = {
      direct: {
        icon: 'envelope',
        meta: formatMessage(messages.direct_long),
        name: 'direct',
        text: formatMessage(messages.direct_short),
      },
      private: {
        icon: 'lock',
        meta: formatMessage(messages.private_long),
        name: 'private',
        text: formatMessage(messages.private_short),
      },
      public: {
        icon: 'globe',
        meta: formatMessage(messages.public_long),
        name: 'public',
        text: formatMessage(messages.public_short),
      },
      unlisted: {
        icon: 'unlock',
        meta: formatMessage(messages.unlisted_long),
        name: 'unlisted',
        text: formatMessage(messages.unlisted_short),
      },
    };

    const items = [privacyItems.public, privacyItems.unlisted, privacyItems.private];

    if (!noDirect) {
      items.push(privacyItems.direct);
    }

    return (
      <Dropdown
        disabled={disabled}
        icon={(privacyItems[value] || {}).icon}
        items={items}
        onChange={onChange}
        isUserTouching={isUserTouching}
        onModalClose={onModalClose}
        onModalOpen={onModalOpen}
        title={formatMessage(messages.change_privacy)}
        container={container}
        value={value}
      />
    );
  }

}