Make prefs load at launch but lazy-load tabs

This commit is contained in:
Ben Gotow 2017-09-04 22:42:08 -07:00
parent 5f7bf08912
commit ad8b538763
12 changed files with 47 additions and 52 deletions

View file

@ -2,13 +2,12 @@ import {PreferencesUIStore, ExtensionRegistry, ComponentRegistry} from 'nylas-ex
import SignatureComposerExtension from './signature-composer-extension'; import SignatureComposerExtension from './signature-composer-extension';
import SignatureComposerDropdown from './signature-composer-dropdown'; import SignatureComposerDropdown from './signature-composer-dropdown';
import PreferencesSignatures from "./preferences-signatures";
export function activate() { export function activate() {
this.preferencesTab = new PreferencesUIStore.TabItem({ this.preferencesTab = new PreferencesUIStore.TabItem({
tabId: "Signatures", tabId: "Signatures",
displayName: "Signatures", displayName: "Signatures",
component: PreferencesSignatures, componentClassFn: () => require('./preferences-signatures').default, // eslint-disable-line
}); });
ExtensionRegistry.Composer.register(SignatureComposerExtension); ExtensionRegistry.Composer.register(SignatureComposerExtension);

View file

@ -96,8 +96,8 @@ export default class SignatureComposerDropdown extends React.Component {
} }
_renderSignatures() { _renderSignatures() {
const header = [<div className="item item-none" key="none" onMouseDown={this._onClickNoSignature}><span>No signature</span></div>] const header = [<div className="item item-none" key="none" onClick={this._onClickNoSignature}><span>No signature</span></div>]
const footer = [<div className="item item-edit" key="edit" onMouseDown={this._onClickEditSignatures}><span>Edit Signatures...</span></div>] const footer = [<div className="item item-edit" key="edit" onClick={this._onClickEditSignatures}><span>Edit Signatures...</span></div>]
const sigItems = Object.values(this.state.signatures) const sigItems = Object.values(this.state.signatures)
return ( return (

View file

@ -9,7 +9,7 @@ export function activate(state = {}) {
this.preferencesTab = new PreferencesUIStore.TabItem({ this.preferencesTab = new PreferencesUIStore.TabItem({
tabId: 'Quick Replies', tabId: 'Quick Replies',
displayName: 'Quick Replies', displayName: 'Quick Replies',
component: require('./preferences-templates').default, componentClassFn: () => require('./preferences-templates').default,
}); });
ComponentRegistry.register(TemplatePicker, {role: 'Composer:ActionButton'}); ComponentRegistry.register(TemplatePicker, {role: 'Composer:ActionButton'});
ComponentRegistry.register(TemplateStatusBar, {role: 'Composer:Footer'}); ComponentRegistry.register(TemplateStatusBar, {role: 'Composer:Footer'});

View file

@ -80,8 +80,8 @@ class TemplatePopover extends React.Component {
]; ];
const footerComponents = [ const footerComponents = [
<div className="item" key="new" onMouseDown={this._onNewTemplate}>Save Draft as Template...</div>, <div className="item" key="new" onClick={this._onNewTemplate}>Save Draft as Template...</div>,
<div className="item" key="manage" onMouseDown={this._onManageTemplates}>Manage Templates...</div>, <div className="item" key="manage" onClick={this._onManageTemplates}>Manage Templates...</div>,
]; ];
return ( return (

View file

@ -1,50 +1,47 @@
import {PreferencesUIStore, /* eslint global-require: 0 */
import {
PreferencesUIStore,
WorkspaceStore, WorkspaceStore,
ComponentRegistry} from 'nylas-exports'; ComponentRegistry,
} from 'nylas-exports';
import PreferencesRoot from './preferences-root'; import PreferencesRoot from './preferences-root';
import PreferencesGeneral from './tabs/preferences-general';
import PreferencesAccounts from './tabs/preferences-accounts';
import PreferencesAppearance from './tabs/preferences-appearance';
import PreferencesKeymaps from './tabs/preferences-keymaps';
import PreferencesMailRules from './tabs/preferences-mail-rules';
import PreferencesIdentity from './tabs/preferences-identity';
export function activate() { export function activate() {
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'General', tabId: 'General',
displayName: 'General', displayName: 'General',
component: PreferencesGeneral, componentClassFn: () => require('./tabs/preferences-general').default,
order: 1, order: 1,
})) }))
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'Accounts', tabId: 'Accounts',
displayName: 'Accounts', displayName: 'Accounts',
component: PreferencesAccounts, componentClassFn: () => require('./tabs/preferences-accounts').default,
order: 2, order: 2,
})) }))
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'Subscription', tabId: 'Subscription',
displayName: 'Subscription', displayName: 'Subscription',
component: PreferencesIdentity, componentClassFn: () => require('./tabs/preferences-identity').default,
order: 3, order: 3,
})) }))
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'Appearance', tabId: 'Appearance',
displayName: 'Appearance', displayName: 'Appearance',
component: PreferencesAppearance, componentClassFn: () => require('./tabs/preferences-appearance').default,
order: 4, order: 4,
})) }))
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'Shortcuts', tabId: 'Shortcuts',
displayName: 'Shortcuts', displayName: 'Shortcuts',
component: PreferencesKeymaps, componentClassFn: () => require('./tabs/preferences-keymaps').default,
order: 5, order: 5,
})) }))
PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({ PreferencesUIStore.registerPreferencesTab(new PreferencesUIStore.TabItem({
tabId: 'Mail Rules', tabId: 'Mail Rules',
displayName: 'Mail Rules', displayName: 'Mail Rules',
component: PreferencesMailRules, componentClassFn: () => require('./tabs/preferences-mail-rules').default,
order: 6, order: 6,
})) }))

View file

@ -77,6 +77,7 @@ class PreferencesRoot extends React.Component {
render() { render() {
const {tab, selection, tabs} = this.props const {tab, selection, tabs} = this.props
const TabComponent = tab && tab.componentClassFn();
return ( return (
<KeyCommandsRegion className="preferences-wrap" tabIndex="1" localHandlers={this._localHandlers()}> <KeyCommandsRegion className="preferences-wrap" tabIndex="1" localHandlers={this._localHandlers()}>
@ -88,7 +89,7 @@ class PreferencesRoot extends React.Component {
<ScrollRegion className="preferences-content"> <ScrollRegion className="preferences-content">
<ConfigPropContainer ref={(el) => { this._contentComponent = el; }}> <ConfigPropContainer ref={(el) => { this._contentComponent = el; }}>
{tab ? {tab ?
<tab.component accountId={selection.accountId} /> : <TabComponent accountId={selection.accountId} /> :
false false
} }
</ConfigPropContainer> </ConfigPropContainer>

View file

@ -7,8 +7,7 @@ import { Flexbox } from 'nylas-component-kit';
import displayedKeybindings from './keymaps/displayed-keybindings'; import displayedKeybindings from './keymaps/displayed-keybindings';
import CommandItem from './keymaps/command-item'; import CommandItem from './keymaps/command-item';
class PreferencesKeymaps extends React.Component { export default class PreferencesKeymaps extends React.Component {
static displayName = 'PreferencesKeymaps'; static displayName = 'PreferencesKeymaps';
static propTypes = { static propTypes = {
@ -135,7 +134,4 @@ class PreferencesKeymaps extends React.Component {
</div> </div>
); );
} }
} }
export default PreferencesKeymaps;

View file

@ -158,7 +158,7 @@ class PreferencesMailRules extends React.Component {
mode={RetinaImg.Mode.ContentDark} mode={RetinaImg.Mode.ContentDark}
/> />
<h2>No rules</h2> <h2>No rules</h2>
<button className="btn btn-small" onMouseDown={this._onAddRule}> <button className="btn btn-small" onClick={this._onAddRule}>
Create a new rule Create a new rule
</button> </button>
</div> </div>

View file

@ -4,6 +4,7 @@
"main": "./lib/main", "main": "./lib/main",
"description": "Nylas Preferences Window Component", "description": "Nylas Preferences Window Component",
"license": "GPL-3.0", "license": "GPL-3.0",
"syncInit": true,
"private": true, "private": true,
"engines": { "engines": {
"merani": "*" "merani": "*"

View file

@ -5,7 +5,7 @@ export function activate() {
this.preferencesTab = new PreferencesUIStore.TabItem({ this.preferencesTab = new PreferencesUIStore.TabItem({
tabId: "Plugins", tabId: "Plugins",
displayName: "Plugins", displayName: "Plugins",
component: PluginsView, componentClassFn: () => PluginsView,
}); });
PreferencesUIStore.registerPreferencesTab(this.preferencesTab); PreferencesUIStore.registerPreferencesTab(this.preferencesTab);

View file

@ -236,10 +236,10 @@ export default class DraftEditingSession extends NylasStore {
// //
// If the account is updated it makes a request to delete the draft with the // If the account is updated it makes a request to delete the draft with the
// old accountId // old accountId
ensureCorrectAccount({noSyncback} = {}) { async ensureCorrectAccount({noSyncback} = {}) {
const account = AccountStore.accountForEmail(this._draft.from[0].email); const account = AccountStore.accountForEmail(this._draft.from[0].email);
if (!account) { if (!account) {
return Promise.reject(new Error("DraftEditingSession::ensureCorrectAccount - you can only send drafts from a configured account.")) throw new Error("DraftEditingSession::ensureCorrectAccount - you can only send drafts from a configured account.");
} }
if (account.id !== this._draft.accountId) { if (account.id !== this._draft.accountId) {
@ -251,12 +251,13 @@ export default class DraftEditingSession extends NylasStore {
threadId: null, threadId: null,
replyToMessageId: null, replyToMessageId: null,
}); });
return this.changes.commit({noSyncback}).thenReturn(this); await this.changes.commit({noSyncback});
} }
return Promise.resolve(this);
return this;
} }
_setDraft(draft) { async _setDraft(draft) {
if (draft.body === undefined) { if (draft.body === undefined) {
throw new Error("DraftEditingSession._setDraft - new draft has no body!"); throw new Error("DraftEditingSession._setDraft - new draft has no body!");
} }
@ -269,28 +270,27 @@ export default class DraftEditingSession extends NylasStore {
fragment.appendChild(draftBodyRootNode); fragment.appendChild(draftBodyRootNode);
draftBodyRootNode.innerHTML = draft.body; draftBodyRootNode.innerHTML = draft.body;
return Promise.each(extensions, (ext) => { for (const ext of extensions) {
if (ext.applyTransformsForSending && ext.unapplyTransformsForSending) { if (ext.applyTransformsForSending && ext.unapplyTransformsForSending) {
Promise.resolve(ext.unapplyTransformsForSending({ await ext.unapplyTransformsForSending({
draftBodyRootNode: draftBodyRootNode, draftBodyRootNode: draftBodyRootNode,
draft: draft, draft: draft,
})); });
} }
}).then(() => { }
draft.body = draftBodyRootNode.innerHTML; draft.body = draftBodyRootNode.innerHTML;
this._draft = draft; this._draft = draft;
// We keep track of the draft's initial body if it's pristine when the editing // We keep track of the draft's initial body if it's pristine when the editing
// session begins. This initial value powers things like "are you sure you want // session begins. This initial value powers things like "are you sure you want
// to send with an empty body?" // to send with an empty body?"
if (draft.pristine) { if (draft.pristine) {
this._draftPristineBody = draft.body; this._draftPristineBody = draft.body;
this._undoStack.save(this._snapshot()); this._undoStack.save(this._snapshot());
} }
this.trigger(); this.trigger();
return Promise.resolve(this); return this;
});
} }
_onDraftChanged = (change) => { _onDraftChanged = (change) => {

View file

@ -32,8 +32,9 @@ export default class ReprocessMailRulesTask extends Task {
// TODO BG WHAT? // TODO BG WHAT?
performRemote() { async performRemote() {
return Promise.fromCallback(this._processAllMessages).thenReturn(Task.Status.Success); await Promise.fromCallback(this._processAllMessages)
return Task.Status.Success;
} }
_processAllMessages = (callback) => { _processAllMessages = (callback) => {