Mailspring/internal_packages/personal-level-indicators/lib/personal-level-icon.jsx
Ben Gotow 94badcda15 es6(*): convert 20+ source files used in example packages to ES2016
There could be a few lurking bugs. Please test!
2016-02-29 18:47:22 -08:00

47 lines
1.4 KiB
JavaScript

import {React} from 'nylas-exports';
export default class PersonalLevelIcon extends React.Component {
// Note: You should assign a new displayName to avoid naming
// conflicts when injecting your item
static displayName = 'PersonalLevelIcon';
static propTypes = {
thread: React.PropTypes.object.isRequired,
};
// In the constructor, we're setting the component's initial state.
constructor(props) {
super(props);
this.state = {
level: this._calculateLevel(this.props.thread),
};
}
// Some more application logic which is specific to this package to decide
// what level of personalness is related to the `thread`.
_calculateLevel = (thread)=> {
const hasMe = thread.participants.filter(p=> p.isMe()).length > 0;
const numOthers = hasMe ? thread.participants.length - 1 : thread.participants.length;
if (!hasMe) { return 0; }
if (numOthers > 1) { return 1; }
if (numOthers === 1) { return 2; }
return 3;
}
// React components' `render` methods return a virtual DOM element to render.
// The returned DOM fragment is a result of the component's `state` and
// `props`. In that sense, `render` methods are deterministic.
render() {
const levelCharacter = ["", "\u3009", "\u300b", "\u21ba"][this.state.level];
return (
<div className="personal-level-icon">
{levelCharacter}
</div>
);
}
}
module.exports = PersonalLevelIcon