~cytrogen/masto-fe

ref: 5c79cd6cf732c348b3cf63e9e6c79d189e42d08d masto-fe/app/javascript/flavours/glitch/components/status_prepend.jsx -rw-r--r-- 3.7 KiB
5c79cd6c — Cytrogen [chore] Add .gstack/ to gitignore 5 days 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
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
//  Package imports  //
import PropTypes from "prop-types";
import { PureComponent } from "react";

import { FormattedMessage } from "react-intl";

import ImmutablePropTypes from "react-immutable-proptypes";

import { Icon } from "flavours/glitch/components/icon";
import { me } from "flavours/glitch/initial_state";

export default class StatusPrepend extends PureComponent {

  static propTypes = {
    type: PropTypes.string.isRequired,
    account: ImmutablePropTypes.map.isRequired,
    parseClick: PropTypes.func.isRequired,
    notificationId: PropTypes.number,
  };

  handleClick = (e) => {
    const { account, parseClick } = this.props;
    parseClick(e, `/@${account.get("acct")}`);
  };

  Message = () => {
    const { type, account } = this.props;
    let link = (
      <a
        onClick={this.handleClick}
        href={account.get("url")}
        className='status__display-name'
      >
        <b
          dangerouslySetInnerHTML={{
            __html : account.get("display_name_html") || account.get("username"),
          }}
        />
      </a>
    );
    switch (type) {
      case "featured":
        return (
          <FormattedMessage id='status.pinned' defaultMessage='Pinned post' />
        );
      case "reblogged_by":
        return (
          <FormattedMessage
            id='status.reblogged_by'
            defaultMessage='{name} boosted'
            values={{ name : link }}
          />
        );
      case "favourite":
        return (
          <FormattedMessage
            id='notification.favourite'
            defaultMessage='{name} favorited your status'
            values={{ name : link }}
          />
        );
      case "reblog":
        return (
          <FormattedMessage
            id='notification.reblog'
            defaultMessage='{name} boosted your status'
            values={{ name : link }}
          />
        );
      case "status":
        return (
          <FormattedMessage
            id='notification.status'
            defaultMessage='{name} just posted'
            values={{ name: link }}
          />
        );
      case "poll":
        if (me === account.get("id")) {
          return (
            <FormattedMessage
              id='notification.own_poll'
              defaultMessage='Your poll has ended'
            />
          );
        } else {
          return (
            <FormattedMessage
              id='notification.poll'
              defaultMessage='A poll you have voted in has ended'
            />
          );
        }
      case "update":
        return (
          <FormattedMessage
            id='notification.update'
            defaultMessage='{name} edited a post'
            values={{ name: link }}
          />
        );
    }
    return null;
  };

  render () {
    const { Message } = this;
    const { type } = this.props;

    let iconId;

    switch(type) {
      case "favourite":
        iconId = "star";
        break;
      case "featured":
        iconId = "thumb-tack";
        break;
      case "poll":
        iconId = "tasks";
        break;
      case "reblog":
      case "reblogged_by":
        iconId = "retweet";
        break;
      case "status":
        iconId = "bell";
        break;
      case "update":
        iconId = "pencil";
        break;
    }

    return !type ? null : (
      <aside className={type === "reblogged_by" || type === "featured" ? "status__prepend" : "notification__message"}>
        <div className={type === "reblogged_by" || type === "featured" ? "status__prepend-icon-wrapper" : "notification__favourite-icon-wrapper"}>
          <Icon
            className={`status__prepend-icon ${type === "favourite" ? "star-icon" : ""}`}
            id={iconId}
          />
        </div>
        <Message />
      </aside>
    );
  }

}