fix(phishing): Tie to MessageStore so it works when msgs aren't ready

This commit is contained in:
Ben Gotow 2016-03-03 14:39:15 -08:00
parent 84b92af0e7
commit 092fb99a17

View file

@ -15,18 +15,34 @@ class PhishingIndicator extends React.Component {
// Adding a displayName to a React component helps for debugging. // Adding a displayName to a React component helps for debugging.
static displayName = 'PhishingIndicator'; static displayName = 'PhishingIndicator';
// @propTypes is an object which validates the datatypes of properties that constructor() {
// this React component can receive. super();
static propTypes = { this.state = {
thread: React.PropTypes.object.isRequired, message: MessageStore.items()[0],
}; };
}
componentDidMount() {
this._unlisten = MessageStore.listen(this._onMessagesChanged);
}
componentWillUnmount() {
if (this._unlisten) {
this._unlisten();
}
}
_onMessagesChanged = () => {
this.setState({
message: MessageStore.items()[0],
});
}
// A React component's `render` method returns a virtual DOM element described // A React component's `render` method returns a virtual DOM element described
// in CJSX. `render` is deterministic: with the same input, it will always // in CJSX. `render` is deterministic: with the same input, it will always
// render the same output. Here, the input is provided by @isPhishingAttempt. // render the same output. Here, the input is provided by @isPhishingAttempt.
// `@state` and `@props` are popular inputs as well. // `@state` and `@props` are popular inputs as well.
render() { render() {
const message = MessageStore.items()[0]; const {message} = this.state;
// This package's strategy to ascertain whether or not the email is a // This package's strategy to ascertain whether or not the email is a
// phishing attempt boils down to checking the `replyTo` attributes on // phishing attempt boils down to checking the `replyTo` attributes on