~cytrogen/masto-fe

ref: bc69d48652e431b06a1fff2c3fd0a67b54d23f81 masto-fe/app/javascript/flavours/glitch/features/compose/components/publisher.jsx -rw-r--r-- 3.5 KiB
bc69d486 — Cytrogen Cherry-pick PR #104: Reduced motion accessibility a month ago
                                                                                
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
import PropTypes from "prop-types";

import { defineMessages, injectIntl } from "react-intl";

import classNames from "classnames";

import ImmutablePureComponent from "react-immutable-pure-component";

import { length } from "stringz";

import Button from "flavours/glitch/components/button";
import { Icon } from "flavours/glitch/components/icon";
import { maxChars } from "flavours/glitch/initial_state";

const messages = defineMessages({
  publish: {
    defaultMessage: "Promulgate",
    id: "compose_form.publish",
  },
  publishLoud: {
    defaultMessage: "{publish}!",
    id: "compose_form.publish_loud",
  },
  saveChanges: { id: "compose_form.save_changes", defaultMessage: "Save changes" },
  public: { id: "privacy.public.short", defaultMessage: "Public" },
  unlisted: { id: "privacy.unlisted.short", defaultMessage: "Unlisted" },
  private: { id: "privacy.private.short", defaultMessage: "Followers only" },
  direct: { id: "privacy.direct.short", defaultMessage: "Mentioned people only" },
});

class Publisher extends ImmutablePureComponent {

  static propTypes = {
    countText: PropTypes.string,
    disabled: PropTypes.bool,
    intl: PropTypes.object.isRequired,
    onSecondarySubmit: PropTypes.func,
    onSubmit: PropTypes.func,
    privacy: PropTypes.oneOf(["direct", "private", "unlisted", "public"]),
    sideArm: PropTypes.oneOf(["none", "direct", "private", "unlisted", "public"]),
    isEditing: PropTypes.bool,
  };

  handleSubmit = () => {
    this.props.onSubmit();
  };

  render () {
    const { countText, disabled, intl, onSecondarySubmit, privacy, sideArm, isEditing } = this.props;

    const diff = maxChars - length(countText || "");
    const computedClass = classNames("compose-form__publish", {
      disabled: disabled,
      over: diff < 0,
    });

    const privacyIcons = { direct: "envelope", private: "lock", public: "globe", unlisted: "unlock" };

    let publishText;
    if (isEditing) {
      publishText = intl.formatMessage(messages.saveChanges);
    } else if (privacy === "private" || privacy === "direct") {
      const iconId = privacyIcons[privacy];
      publishText = (
        <span>
          <Icon id={iconId} /> {intl.formatMessage(messages.publish)}
        </span>
      );
    } else {
      publishText = privacy !== "unlisted" ? intl.formatMessage(messages.publishLoud, { publish: intl.formatMessage(messages.publish) }) : intl.formatMessage(messages.publish);
    }

    const privacyNames = {
      public: messages.public,
      unlisted: messages.unlisted,
      private: messages.private,
      direct: messages.direct,
    };

    return (
      <div className={computedClass}>
        {sideArm && !isEditing && sideArm !== "none" ? (
          <div className='compose-form__publish-button-wrapper'>
            <Button
              className='side_arm'
              disabled={disabled}
              onClick={onSecondarySubmit}
              style={{ padding: null }}
              text={<Icon id={privacyIcons[sideArm]} />}
              title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[sideArm])}`}
            />
          </div>
        ) : null}
        <div className='compose-form__publish-button-wrapper'>
          <Button
            className='primary'
            text={publishText}
            title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage(privacyNames[privacy])}`}
            onClick={this.handleSubmit}
            disabled={disabled}
          />
        </div>
      </div>
    );
  }

}

export default injectIntl(Publisher);