Mailspring/internal_packages/message-list/lib/message-list-hidden-messages-toggle.jsx
Ben Gotow f413386b80 feat(hidden-messages): Filter trash/spam messages. Fixes #1135
Summary:
By default, the messages in a thread are now filtered to exclude
ones moved to trash or spam. You can choose to view those messages by clicking
the new bar in the message list.

When you view your spam or trash, we only show the messages on those threads
that have been marked as spam/trash.

Test Plan: Run a couple new tests

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2662
2016-03-02 10:05:17 -08:00

64 lines
1.7 KiB
JavaScript

import {
React,
Actions,
MessageStore,
FocusedPerspectiveStore,
} from 'nylas-exports';
export default class MessageListHiddenMessagesToggle extends React.Component {
static displayName = 'MessageListHiddenMessagesToggle';
constructor() {
super();
this.state = {
numberOfHiddenItems: MessageStore.numberOfHiddenItems(),
};
}
componentDidMount() {
this._unlisten = MessageStore.listen(() => {
this.setState({
numberOfHiddenItems: MessageStore.numberOfHiddenItems(),
});
});
}
componentWillUnmount() {
this._unlisten();
}
render() {
const {numberOfHiddenItems} = this.state;
if (numberOfHiddenItems === 0) {
return false;
}
const viewing = FocusedPerspectiveStore.current().categoriesSharedName();
let message = null;
if (MessageStore.CategoryNamesHiddenByDefault.includes(viewing)) {
if (numberOfHiddenItems > 1) {
message = `There are ${numberOfHiddenItems} more messages in this thread that are not in spam or trash.`;
} else {
message = `There is one more message in this thread that is not in spam or trash.`;
}
} else {
if (numberOfHiddenItems > 1) {
message = `${numberOfHiddenItems} messages in this thread are hidden because it was moved to trash or spam.`;
} else {
message = `One message in this thread is hidden because it was moved to trash or spam.`;
}
}
return (
<div className="show-hidden-messages">
{message}
<a onClick={function toggle() { Actions.toggleHiddenMessages() }}>Show all messages</a>
</div>
);
}
}
MessageListHiddenMessagesToggle.containerRequired = false;