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

const messages = defineMessages({
  change_privacy: {
    defaultMessage: 'Adjust status privacy',
    id: 'privacy.change',
  },
  direct_long: {
    defaultMessage: 'Visible for mentioned users only',
    id: 'privacy.direct.long',
  },
  direct_short: {
    defaultMessage: 'Direct',
    id: 'privacy.direct.short',
  },
  private_long: {
    defaultMessage: 'Visible for followers only',
    id: 'privacy.private.long',
  },
  private_short: {
    defaultMessage: 'Followers-only',
    id: 'privacy.private.short',
  },
  public_long: {
    defaultMessage: 'Visible for all, shown in public timelines',
    id: 'privacy.public.long',
  },
  public_short: {
    defaultMessage: 'Public',
    id: 'privacy.public.short',
  },
  unlisted_long: {
    defaultMessage: 'Visible for all, but not in public timelines',
    id: 'privacy.unlisted.long',
  },
  unlisted_short: {
    defaultMessage: 'Unlisted',
    id: 'privacy.unlisted.short',
  },
});

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,
    noModal: PropTypes.bool,
    container: PropTypes.func,
    intl: PropTypes.object.isRequired,
  };

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

    //  We predefine our privacy items so that we can easily pick the
    //  dropdown icon later.
    const privacyItems = {
      direct: {
        icon: 'envelope',
        meta: <FormattedMessage {...messages.direct_long} />,
        name: 'direct',
        text: <FormattedMessage {...messages.direct_short} />,
      },
      private: {
        icon: 'lock',
        meta: <FormattedMessage {...messages.private_long} />,
        name: 'private',
        text: <FormattedMessage {...messages.private_short} />,
      },
      public: {
        icon: 'globe',
        meta: <FormattedMessage {...messages.public_long} />,
        name: 'public',
        text: <FormattedMessage {...messages.public_short} />,
      },
      unlisted: {
        icon: 'unlock',
        meta: <FormattedMessage {...messages.unlisted_long} />,
        name: 'unlisted',
        text: <FormattedMessage {...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}
        onModalClose={onModalClose}
        onModalOpen={onModalOpen}
        title={intl.formatMessage(messages.change_privacy)}
        container={container}
        noModal={noModal}
        value={value}
      />
    );
  }

}