Mailspring/internal_packages/preferences/lib/tabs/preferences-account-list.jsx

65 lines
1.9 KiB
React
Raw Normal View History

feat(account-prefs): Adds new page for Account in preferences Summary: Adds the new Account preferences page. This consists of two major React components, PreferencesAccountList and PreferencesAccountDetails, both of which use EditableList. I added a bunch of fixes and updated the API for EditableList, plus a bit of refactoring for PreferencesAccount component, and a bunch of CSS so its a big diff. The detailed changelog: Updates to EditableList: - Fix bug updating selection state when arrows pressed to move selection - Add new props: - allowEmptySelection to allow the list to have no selection - createInputProps to pass aditional props to the createInput - Add scroll region for list items - Update styles and refactor render methods Other Updates: - Updates Account model to hold aliases and a label - Adds getter for label to default to email - Update accountswitcher to display label, update styles and spec - Refactor PreferencesAccounts component: - Splits it into smaller components, - Removes unused code - Splits preferences styelsheets into smaller separate stylesheet for account page. Adds some updates and fixes (scroll-region padding) - Update AccountStore to be able to perform updates on an account. - Adds new Action to update account, and an action to remove account to be consistent with Action usage - Adds components for Account list and Aliases list using EditableList Test Plan: - All specs pass, but need to write new tests! Reviewers: bengotow, evan Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D2332
2015-12-10 04:35:40 +08:00
import React, {Component, PropTypes} from 'react';
import {RetinaImg, Flexbox, EditableList} from 'nylas-component-kit';
class PreferencesAccountList extends Component {
static propTypes = {
accounts: PropTypes.array,
onAddAccount: PropTypes.func.isRequired,
onAccountSelected: PropTypes.func.isRequired,
onRemoveAccount: PropTypes.func.isRequired,
}
_onAccountSelected = (accountComp, idx)=> {
this.props.onAccountSelected(this.props.accounts[idx], idx);
}
_onRemoveAccount = (accountComp, idx)=> {
this.props.onRemoveAccount(this.props.accounts[idx], idx);
}
_renderAccount = (account)=> {
const label = account.label;
const accountSub = `${account.name || 'No name provided'} <${account.emailAddress}>`;
return (
<div
className="account"
key={account.id} >
<Flexbox direction="row" style={{alignItems: 'middle'}}>
<div style={{textAlign: 'center'}}>
<RetinaImg
name={`ic-settings-account-${account.provider}.png`}
fallback="ic-settings-account-imap.png"
mode={RetinaImg.Mode.ContentPreserve} />
</div>
<div style={{flex: 1, marginLeft: 10}}>
<div className="account-name">{label}</div>
<div className="account-subtext">{accountSub} ({account.displayProvider()})</div>
</div>
</Flexbox>
</div>
);
}
render() {
if (!this.props.accounts) {
return <div className="account-list"></div>;
}
return (
<div className="account-list">
<EditableList
allowEmptySelection={false}
onCreateItem={this.props.onAddAccount}
onItemSelected={this._onAccountSelected}
onDeleteItem={this._onRemoveAccount}>
{this.props.accounts.map(this._renderAccount)}
</EditableList>
</div>
);
}
}
export default PreferencesAccountList;