Mailspring/app/internal_packages_disabled/thread-unsubscribe/lib/thread-unsubscribe-button.tsx
Ben Gotow 21bc2ef398
Upgrade to Slate 0.45.1 for better composer perf and "setStart on Range" error fix (#1518)
* Move to Slate 44, start using types more extensively in Composer

* More types and cleanup

* Expose the editor object to the draft session, try exposing editor to session

* Bump to Slate 45 for https://github.com/ianstormtaylor/slate/pull/2225/files

* How did the unsubscribe plugin get in here

* Bump Slate types, fix TS errors, start testing

* Polish

* Fix issue with emails not shrinking when you close quoted text

* Fix the “remove quoted text” button

* More polish

* Fix issues with PR, improve typings

* Remove spurious log
2019-06-10 19:15:07 -05:00

69 lines
1.6 KiB
TypeScript

import React from 'react';
import { Message, localized, PropTypes, Thread } from 'mailspring-exports';
import { RetinaImg, BindGlobalCommands } from 'mailspring-component-kit';
function unsubscribe(message) {
//
}
function canUnsubscribe(message) {
if (message.extraHeaders && message.extraHeaders['X-UNSUBSCRIBE'] !== null) {
return true;
}
if (message.body) {
console.log('got body!');
}
}
export default class ThreadUnsubscribeButton extends React.Component<{
items: Thread[];
message: Message;
}> {
static displayName = 'ThreadUnsubscribeButton';
static containerRequired = false;
static propTypes = { message: PropTypes.instanceOf(Message).isRequired };
state = {
v: 0,
};
_mounted: boolean = false;
componentDidMount() {
this._mounted = true;
}
componentWillUnmount() {
this._mounted = false;
}
_onClick = async () => {
const message = this.props.items.find(canUnsubscribe);
if (!message) return;
this.setState({ v: this.state.v + 1 });
await unsubscribe(message);
if (!this._mounted) return;
this.setState({ v: this.state.v + 1 });
};
render() {
if (!canUnsubscribe(this.props.message)) {
return <span />;
}
return (
<BindGlobalCommands commands={{ 'core:unsubscribe': () => this._onClick() }}>
<button
className={`btn btn-toolbar thread-unsubscribe-button`}
title={localized('Share')}
style={{ marginRight: 0 }}
onClick={this._onClick}
>
<RetinaImg name="ic-toolbar-native-share.png" mode={RetinaImg.Mode.ContentIsMask} />
</button>
</BindGlobalCommands>
);
}
}