import React from 'react'; import DropDownBase from './DropDownBase.js'; export default class AccountFolders extends React.PureComponent { state = { collapsed: this.props.collapsed, animating: false, h: null, cfgPressed: false, } render() { return
{this.props.account.email || this.props.account.name}
{this.props.account.unreadCount}
{this.props.account.accountId ? [
,
,
] : null}
{this.props.account.folders.map((f, i) =>
0 ? ' with-unread' : '')+ (this.props.selected == i ? ' selected' : '')} onClick={this.selectFolder}> {f.icon ? : null} {' '} {f.name} {f.unreadCount > 0 ?
{f.unreadCount}
: null}
)}
} selectFolder = (ev) => { let t = ev.target; while (t && !t.getAttribute('data-i') && t != this.refs.vis) t = t.parentNode; if (t && t != this.refs.vis) { let i = t.getAttribute('data-i'); this.props.onSelect(this.props.accountIndex, i); } // FIXME: send select event + switch focus to message list if folder changed } showCfg = (ev) => { let i = DropDownBase.instances.account.state.items; i[0].text = 'Read '+(this.props.account.email||this.props.account.name); DropDownBase.instances.account.setState({ items: i }); DropDownBase.instances.account.showAt(ev.target, () => { this.setState({ cfgPressed: false }); }); this.setState({ cfgPressed: true }); ev.stopPropagation(); } onClick = () => { if (this.state.animating) return; this.setState({ animating: true, h: this.refs.vis.offsetHeight }); if (!this.state.collapsed) { setTimeout(() => { this.setState({ h: 0 }); }, 50); } setTimeout(() => { this.setState({ collapsed: !this.state.collapsed, animating: false, h: null }); }, this.state.collapsed ? 200 : 250); } }