Mailspring/app/internal_packages/preferences/lib/preferences-root.tsx
Ben Gotow 149b389508
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-04 11:03:12 -08:00

107 lines
3.3 KiB
TypeScript

/* eslint jsx-a11y/tabindex-no-positive: 0 */
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import {
Flexbox,
ScrollRegion,
KeyCommandsRegion,
ListensToFluxStore,
ConfigPropContainer,
} from 'mailspring-component-kit';
import { PreferencesUIStore } from 'mailspring-exports';
import PreferencesTabsBar from './preferences-tabs-bar';
const stopPropagation = e => {
e.stopPropagation();
};
class PreferencesRoot extends React.Component<{ tab: any; tabs: any[]; selection: any }> {
static displayName = 'PreferencesRoot';
// This prevents some basic commands from propagating to the threads list and
// producing unexpected results
// TODO This is a partial/temporary solution and should go away when we do the
// Keymap/Commands/Menu refactor
_localHandlers = {
'core:next-item': stopPropagation,
'core:previous-item': stopPropagation,
'core:select-up': stopPropagation,
'core:select-down': stopPropagation,
'core:select-item': stopPropagation,
'core:messages-page-up': stopPropagation,
'core:messages-page-down': stopPropagation,
'core:list-page-up': stopPropagation,
'core:list-page-down': stopPropagation,
'core:remove-from-view': stopPropagation,
'core:gmail-remove-from-view': stopPropagation,
'core:remove-and-previous': stopPropagation,
'core:remove-and-next': stopPropagation,
'core:archive-item': stopPropagation,
'core:delete-item': stopPropagation,
'core:print-thread': stopPropagation,
};
_contentComponent: ConfigPropContainer;
componentDidMount() {
(ReactDOM.findDOMNode(this) as HTMLElement).focus();
this._focusContent();
}
componentDidUpdate(oldProps) {
if (oldProps.tab !== this.props.tab) {
const scrollRegion = document.querySelector('.preferences-content .scroll-region-content');
scrollRegion.scrollTop = 0;
this._focusContent();
}
}
// Focus the first thing with a tabindex when we update.
// inside the content area. This makes it way easier to interact with prefs.
_focusContent() {
const contentEl = ReactDOM.findDOMNode(this._contentComponent) as HTMLElement;
const node = contentEl.querySelector('[tabindex]') as HTMLElement;
if (node) {
node.focus();
}
}
render() {
const { tab, selection, tabs } = this.props;
const TabComponent = tab && tab.componentClassFn();
return (
<KeyCommandsRegion
className="preferences-wrap"
tabIndex={1}
localHandlers={this._localHandlers}
>
<Flexbox direction="column">
<PreferencesTabsBar tabs={tabs} selection={selection} />
<ScrollRegion className="preferences-content">
<ConfigPropContainer
ref={el => {
this._contentComponent = el;
}}
>
{tab ? <TabComponent accountId={selection.accountId} /> : null}
</ConfigPropContainer>
</ScrollRegion>
</Flexbox>
</KeyCommandsRegion>
);
}
}
export default ListensToFluxStore(PreferencesRoot, {
stores: [PreferencesUIStore],
getStateFromStores() {
const tabs = PreferencesUIStore.tabs();
const selection = PreferencesUIStore.selection();
const tab = tabs.find(t => t.tabId === selection.tabId);
return { tabs, selection, tab };
},
});