mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-04 07:10:06 +08:00
ae72cf1c65
commit 3c10d22199ea6428a6b45c6361d281b1d281ef4f
Author: Ben Gotow <ben@foundry376.com>
Date: Fri Jan 19 08:10:43 2018 -0800
Small fixes
commit e7d4ba85eb011a6fd58b57e079bf3a19c19126d8
Author: Ben Gotow <ben@foundry376.com>
Date: Thu Jan 18 23:47:03 2018 -0800
Rewrite UnsafeComponent using Error Boundaries
commit aa772694fdee6c57887b75b3abb2e654e146fab5
Author: Ben Gotow <ben@foundry376.com>
Date: Thu Jan 18 23:15:53 2018 -0800
Remove GeneratedForm
commit f9ea4296f07d446f942dfc2532deea37db43ddac
Author: Ben Gotow <ben@foundry376.com>
Date: Thu Jan 18 23:08:45 2018 -0800
Fully remove calendar related dead code and spec_disabled
It’s making it hard to see what I need to edit and what I don’t care about
commit 6192ce6073244bc66b7908b66b5033d34e947efb
Author: Ben Gotow <ben@foundry376.com>
Date: Thu Jan 18 23:08:16 2018 -0800
Bump to React 16.2 🎉
97 lines
2.3 KiB
JavaScript
97 lines
2.3 KiB
JavaScript
import { React, UndoRedoStore } from 'mailspring-exports';
|
|
import { RetinaImg } from 'mailspring-component-kit';
|
|
import { CSSTransitionGroup } from 'react-transition-group';
|
|
|
|
const VISIBLE_DURATION = 3000;
|
|
|
|
export default class UndoRedoToast extends React.Component {
|
|
static displayName = 'UndoRedoToast';
|
|
static containerRequired = false;
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this._timeout = null;
|
|
this._unlisten = null;
|
|
this._mounted = false;
|
|
|
|
// Note: we explicitly do /not/ set initial state to the state of
|
|
// the UndoRedoStore here because "getMostRecent" might be more
|
|
// than 3000ms old.
|
|
this.state = {
|
|
block: null,
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
this._mounted = true;
|
|
this._unlisten = UndoRedoStore.listen(() => {
|
|
this.setState({
|
|
block: UndoRedoStore.getMostRecent(),
|
|
});
|
|
});
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
this._ensureTimeout();
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this._mounted = false;
|
|
this._clearTimeout();
|
|
if (this._unlisten) {
|
|
this._unlisten();
|
|
}
|
|
}
|
|
|
|
_clearTimeout() {
|
|
clearTimeout(this._timeout);
|
|
this._timeout = null;
|
|
}
|
|
|
|
_ensureTimeout() {
|
|
this._clearTimeout();
|
|
|
|
if (this.state.block) {
|
|
this._timeout = setTimeout(() => {
|
|
this._mounted = false;
|
|
this.setState({ block: null });
|
|
}, VISIBLE_DURATION);
|
|
}
|
|
}
|
|
|
|
_onMouseEnter = () => {
|
|
this._clearTimeout();
|
|
};
|
|
|
|
_onMouseLeave = () => {
|
|
this._ensureTimeout();
|
|
};
|
|
|
|
render() {
|
|
const { block } = this.state;
|
|
|
|
return (
|
|
<CSSTransitionGroup
|
|
className="undo-redo-toast"
|
|
transitionLeaveTimeout={150}
|
|
transitionEnterTimeout={150}
|
|
transitionName="undo-redo-toast-fade"
|
|
>
|
|
{block ? (
|
|
<div
|
|
className="content"
|
|
onMouseEnter={this._onMouseEnter}
|
|
onMouseLeave={this._onMouseLeave}
|
|
>
|
|
<div className="message">{block.description}</div>
|
|
<div className="action" onClick={() => AppEnv.commands.dispatch('core:undo')}>
|
|
<RetinaImg name="undo-icon@2x.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
<span className="undo-action-text">Undo</span>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
</CSSTransitionGroup>
|
|
);
|
|
}
|
|
}
|