Mailspring/app/internal_packages/preferences/lib/preferences-tabs-bar.jsx

97 lines
2.2 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types'
import fs from 'fs'
import classNames from 'classnames';
import {Flexbox, RetinaImg} from 'nylas-component-kit';
import {Actions, PreferencesUIStore, Utils} from 'nylas-exports';
class PreferencesTabItem extends React.Component {
static displayName = 'PreferencesTabItem';
static propTypes = {
selection: PropTypes.shape({
accountId: PropTypes.string,
tabId: PropTypes.string,
}).isRequired,
tabItem: PropTypes.instanceOf(PreferencesUIStore.TabItem).isRequired,
}
_onClick = () => {
Actions.switchPreferencesTab(this.props.tabItem.tabId);
}
_onClickAccount = (event, accountId) => {
Actions.switchPreferencesTab(this.props.tabItem.tabId, {accountId});
event.stopPropagation();
}
render() {
feat(undo-send): Add undo send Summary: Add ability to undo send. We decided to make undo send completely client side for a couple of reasons. If we rely on send-later for undo-send, we would be giving /all/ send load to our send-later backend. If this increases the send-later load too much, it might cause delays in the regular send-later functionality and potentially other plugins like snooze that run under the same service. We would also need to rely on the network to be able to cancel a send, which would make it unusable offline or hard to debug if that specific request fails for any given reason. This commit also refactors the way `ComposerExtension.sendActionConfig` works. The method has been renamed and now must return an array of send actions. Also, all of the business logic to handle different send actions registered by extensions has been pieced apart from the SendActionButton and into a new SendActionStore. This also enables undo send to undo custom send actions registered by extensions. Along the way, this also fixes a pending TODO to show all registered custom send actions in the preferences for choosing the preferred send action for sending. Undo send works via a task, so in case N1 closes before send goes through, it will still be persisted to the task queue and restored when opened again. Undoing a send means dequeuing this task. Test Plan: Manual Reviewers: jackie, bengotow, halla, evan Reviewed By: bengotow, halla, evan Differential Revision: https://phab.nylas.com/D3361
2016-10-22 02:48:04 +08:00
const {selection, tabItem} = this.props
const {tabId, displayName} = tabItem;
const classes = classNames({
2016-05-07 07:23:48 +08:00
item: true,
active: tabId === selection.tabId,
});
let path = `icon-preferences-${displayName.toLowerCase().replace(" ", "-")}.png`
if (!fs.existsSync(Utils.imageNamed(path))) {
path = "icon-preferences-general.png";
}
2016-05-07 07:23:48 +08:00
const icon = (
<RetinaImg
className="tab-icon"
name={path}
mode={RetinaImg.Mode.ContentPreserve}
/>
);
return (
<div className={classes} onClick={this._onClick}>
{icon}
<div className="name">{displayName}</div>
</div>
);
}
}
class PreferencesTabsBar extends React.Component {
static displayName = 'PreferencesTabsBar';
static propTypes = {
tabs: PropTypes.array.isRequired,
selection: PropTypes.shape({
accountId: PropTypes.string,
tabId: PropTypes.string,
}).isRequired,
}
renderTabs() {
return this.props.tabs.map((tabItem) =>
<PreferencesTabItem
key={tabItem.tabId}
tabItem={tabItem}
2016-05-07 07:23:48 +08:00
selection={this.props.selection}
/>
);
}
render() {
return (
<div className="container-preference-tabs">
<Flexbox direction="row" className="preferences-tabs">
2016-10-18 08:59:33 +08:00
<div style={{flex: 1}} />
{this.renderTabs()}
2016-10-18 08:59:33 +08:00
<div style={{flex: 1}} />
</Flexbox>
</div>
);
}
}
export default PreferencesTabsBar;