Mailspring/app/src/sheet-container.tsx

174 lines
4.5 KiB
TypeScript
Raw Normal View History

2017-09-27 02:33:08 +08:00
import React from 'react';
import { CSSTransitionGroup } from 'react-transition-group';
import { WorkspaceStore } from 'mailspring-exports';
2017-08-01 13:21:00 +08:00
2017-09-27 02:33:08 +08:00
import Sheet from './sheet';
import Toolbar from './sheet-toolbar';
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
import { Flexbox } from './components/flexbox';
import { InjectedComponentSet } from './components/injected-component-set';
import { SheetDeclaration } from './flux/stores/workspace-store';
interface SheetContainerState {
stack: SheetDeclaration[];
mode: string;
error?: string;
}
2017-08-01 13:21:00 +08:00
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
export default class SheetContainer extends React.Component<{}, SheetContainerState> {
2017-08-01 13:21:00 +08:00
static displayName = 'SheetContainer';
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
_toolbarComponents = {};
unsubscribe?: () => void;
2017-08-01 13:21:00 +08:00
constructor(props) {
super(props);
2017-09-27 02:33:08 +08:00
this.state = this._getStateFromStores();
2017-08-01 13:21:00 +08:00
}
componentDidMount() {
this.unsubscribe = WorkspaceStore.listen(this._onStoreChange);
}
componentDidCatch(error, info) {
// We don't currently display the error, but we need to call setState within
// this function or the component does not re-render after being reset.
this.setState({ error: error.stack });
AppEnv.reportError(error);
}
2017-08-01 13:21:00 +08:00
componentWillUnmount() {
if (this.unsubscribe) {
this.unsubscribe();
}
}
_getStateFromStores() {
return {
stack: WorkspaceStore.sheetStack(),
mode: WorkspaceStore.layoutMode(),
};
}
2017-09-27 02:33:08 +08:00
_onColumnSizeChanged = sheet => {
2017-08-01 13:21:00 +08:00
const toolbar = this._toolbarComponents[sheet.props.depth];
if (toolbar) {
toolbar.recomputeLayout();
}
window.dispatchEvent(new Event('resize'));
2017-09-27 02:33:08 +08:00
};
2017-08-01 13:21:00 +08:00
_onStoreChange = () => {
this.setState(this._getStateFromStores());
2017-09-27 02:33:08 +08:00
};
2017-08-01 13:21:00 +08:00
_lastToolbarClickTime: number = 0;
_onToolbarDoubleClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (process.platform !== 'darwin') return;
if (e.target instanceof HTMLElement) {
if (['INPUT', 'A', 'BUTTON'].includes(e.target.tagName)) return;
if (e.target.hasAttribute('contenteditable')) return;
}
if (Date.now() - this._lastToolbarClickTime < 350) {
const win = AppEnv.getCurrentWindow();
if (win.isMaximized()) {
win.unmaximize();
} else {
win.maximize();
}
}
this._lastToolbarClickTime = Date.now();
};
2017-08-01 13:21:00 +08:00
_toolbarContainerElement() {
2017-09-27 02:36:58 +08:00
const { toolbar } = AppEnv.getLoadSettings();
2017-08-01 13:21:00 +08:00
if (!toolbar) {
return [];
}
2017-09-27 02:33:08 +08:00
const components = this.state.stack.map((sheet, index) => (
2017-08-01 13:21:00 +08:00
<Toolbar
data={sheet}
2017-09-27 02:33:08 +08:00
ref={cm => {
this._toolbarComponents[index] = cm;
}}
2017-08-01 13:21:00 +08:00
key={`${index}:${sheet.id}:toolbar`}
depth={index}
/>
2017-09-27 02:33:08 +08:00
));
2017-08-01 13:21:00 +08:00
return (
<div
className="sheet-toolbar"
style={{ order: 0, zIndex: 3 }}
onClick={this._onToolbarDoubleClick}
>
2017-08-01 13:21:00 +08:00
{components[0]}
<CSSTransitionGroup
2017-08-01 13:21:00 +08:00
transitionLeaveTimeout={125}
transitionEnterTimeout={125}
transitionName="opacity-125ms"
>
{components.slice(1)}
</CSSTransitionGroup>
2017-08-01 13:21:00 +08:00
</div>
);
}
render() {
const totalSheets = this.state.stack.length;
const topSheet = this.state.stack[totalSheets - 1];
if (!topSheet) {
2017-09-27 02:33:08 +08:00
return <div />;
2017-08-01 13:21:00 +08:00
}
2017-09-27 02:33:08 +08:00
const sheetComponents = this.state.stack.map((sheet, index) => (
2017-08-01 13:21:00 +08:00
<Sheet
data={sheet}
depth={index}
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
key={index > 0 ? `${index}:${sheet.id}` : `root`}
2017-08-01 13:21:00 +08:00
onColumnSizeChanged={this._onColumnSizeChanged}
/>
2017-09-27 02:33:08 +08:00
));
2017-08-01 13:21:00 +08:00
return (
<Flexbox
direction="column"
className={`layout-mode-${this.state.mode}`}
2017-09-27 02:33:08 +08:00
style={{ overflow: 'hidden' }}
2017-08-01 13:21:00 +08:00
>
{this._toolbarContainerElement()}
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
<div style={{ order: 1, zIndex: 2 }}>
2017-08-01 13:21:00 +08:00
<InjectedComponentSet
2017-09-27 02:33:08 +08:00
matching={{ locations: [topSheet.Header, WorkspaceStore.Sheet.Global.Header] }}
2017-08-01 13:21:00 +08:00
direction="column"
id={topSheet.id}
/>
</div>
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
<div style={{ order: 2, flex: 1, position: 'relative', zIndex: 1 }}>
2017-08-01 13:21:00 +08:00
{sheetComponents[0]}
<CSSTransitionGroup
2017-08-01 13:21:00 +08:00
transitionLeaveTimeout={125}
transitionEnterTimeout={125}
transitionName="sheet-stack"
>
{sheetComponents.slice(1)}
</CSSTransitionGroup>
2017-08-01 13:21:00 +08:00
</div>
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
<div style={{ order: 3, zIndex: 4 }}>
2017-08-01 13:21:00 +08:00
<InjectedComponentSet
2017-09-27 02:33:08 +08:00
matching={{ locations: [topSheet.Footer, WorkspaceStore.Sheet.Global.Footer] }}
2017-08-01 13:21:00 +08:00
direction="column"
id={topSheet.id}
/>
</div>
</Flexbox>
);
}
}