mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-04 07:10:06 +08:00
Fix small bug where the undo/redo toast re-appears #108
This commit is contained in:
parent
e604c9918e
commit
d72fe51c40
2 changed files with 42 additions and 35 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Mailspring Changelog
|
# Mailspring Changelog
|
||||||
|
|
||||||
### 1.0.4 (Coming Soon)
|
### 1.0.4 (10/12/2017)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,45 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { UndoRedoStore } from 'mailspring-exports';
|
import { UndoRedoStore } from 'mailspring-exports';
|
||||||
import { UndoToast, ListensToFluxStore } from 'mailspring-component-kit';
|
import { UndoToast } from 'mailspring-component-kit';
|
||||||
|
|
||||||
function onUndo() {
|
export default class UndoRedoThreadListToast extends React.Component {
|
||||||
AppEnv.commands.dispatch('core:undo');
|
static displayName = 'UndoRedoThreadListToast';
|
||||||
|
static containerRequired = false;
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
// 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 = { visible: false, tasks: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this._unlisten = UndoRedoStore.listen(() => {
|
||||||
|
const tasks = UndoRedoStore.getMostRecent();
|
||||||
|
this.setState({
|
||||||
|
tasks,
|
||||||
|
visible: tasks && tasks.length > 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this._unlisten) {
|
||||||
|
this._unlisten();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<UndoToast
|
||||||
|
visible={this.state.visible}
|
||||||
|
visibleDuration={3000}
|
||||||
|
className="undo-redo-thread-list-toast"
|
||||||
|
onUndo={() => AppEnv.commands.dispatch('core:undo')}
|
||||||
|
undoMessage={this.state.tasks.map(t => t.description()).join(', ')}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function UndoRedoThreadListToast(props) {
|
|
||||||
const { tasks } = props;
|
|
||||||
return (
|
|
||||||
<UndoToast
|
|
||||||
{...props}
|
|
||||||
onUndo={onUndo}
|
|
||||||
visibleDuration={3000}
|
|
||||||
className="undo-redo-thread-list-toast"
|
|
||||||
undoMessage={tasks.map(t => t.description()).join(', ')}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
UndoRedoThreadListToast.displayName = 'UndoRedoThreadListToast';
|
|
||||||
UndoRedoThreadListToast.containerRequired = false;
|
|
||||||
UndoRedoThreadListToast.propTypes = {
|
|
||||||
tasks: PropTypes.array,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ListensToFluxStore(UndoRedoThreadListToast, {
|
|
||||||
stores: [UndoRedoStore],
|
|
||||||
getStateFromStores() {
|
|
||||||
const tasks = UndoRedoStore.getMostRecent();
|
|
||||||
return {
|
|
||||||
tasks,
|
|
||||||
visible: tasks && tasks.length > 0,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue