2018-12-02 19:27:22 +03:00
|
|
|
import React from 'react';
|
|
|
|
import DropDownBase from './DropDownBase.js';
|
2016-09-11 15:49:57 +03:00
|
|
|
|
2018-12-02 19:27:22 +03:00
|
|
|
export default class AccountFolders extends React.PureComponent
|
|
|
|
{
|
|
|
|
state = {
|
|
|
|
collapsed: this.props.collapsed,
|
|
|
|
animating: false,
|
|
|
|
h: null,
|
|
|
|
cfgPressed: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
render()
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
|
|
|
return <div className="account">
|
|
|
|
<div className={"account-header"+(this.state.collapsed ? ' collapsed' : '')} onClick={this.onClick}>
|
2016-10-02 11:31:27 +03:00
|
|
|
{this.props.account.email || this.props.account.name}
|
|
|
|
<div key="n" className="msg-count">{this.props.account.unreadCount}</div>
|
|
|
|
{this.props.account.accountId ? [
|
|
|
|
<div key="load" className="loading icon" style={{display: this.props.account.loading ? '' : 'none'}}></div>,
|
|
|
|
<div key="warn" className="warning icon" style={{display: this.props.account.warning ? '' : 'none'}}></div>,
|
2016-09-11 15:49:57 +03:00
|
|
|
<div key="cfg" className={'cfg'+(this.state.cfgPressed ? ' pressed' : '')} onClick={this.showCfg}></div>
|
|
|
|
] : null}
|
|
|
|
</div>
|
|
|
|
<div className={"account-folders"+(this.state.collapsed ? ' collapsed' : '')} style={{ height: this.state.h }}>
|
|
|
|
<div ref="vis" className={'visible-part'+(this.state.animating ? ' animating' : '')}>
|
2016-10-02 11:31:27 +03:00
|
|
|
{this.props.account.folders.map((f, i) =>
|
2019-05-20 19:35:47 +03:00
|
|
|
<div key={'f'+i} data-i={i} className={'folder'+(f.type != 'pinned' && f.unreadCount > 0 ? ' with-unread' : '')+
|
2016-10-02 11:31:27 +03:00
|
|
|
(this.props.selected == i ? ' selected' : '')} onClick={this.selectFolder}>
|
2016-09-11 15:49:57 +03:00
|
|
|
{f.icon ? <img src={'icons/'+f.icon+'.png'} /> : null}
|
|
|
|
{' '}
|
|
|
|
<span>{f.name}</span>
|
|
|
|
{f.unreadCount > 0 ? <div className="msg-count">{f.unreadCount}</div> : null}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-02 19:27:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
selectFolder = (ev) =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
let t = ev.target;
|
2016-09-11 15:49:57 +03:00
|
|
|
while (t && !t.getAttribute('data-i') && t != this.refs.vis)
|
|
|
|
t = t.parentNode;
|
|
|
|
if (t && t != this.refs.vis)
|
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
let i = t.getAttribute('data-i');
|
2016-10-02 02:04:16 +03:00
|
|
|
this.props.onSelect(this.props.accountIndex, i);
|
2016-09-11 15:49:57 +03:00
|
|
|
}
|
|
|
|
// FIXME: send select event + switch focus to message list if folder changed
|
2018-12-02 19:27:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
showCfg = (ev) =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
let i = DropDownBase.instances.account.state.items;
|
2016-10-02 11:31:27 +03:00
|
|
|
i[0].text = 'Read '+(this.props.account.email||this.props.account.name);
|
2016-09-11 15:49:57 +03:00
|
|
|
DropDownBase.instances.account.setState({ items: i });
|
2019-05-14 15:49:20 +03:00
|
|
|
DropDownBase.instances.account.showAt(ev.target, () =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
this.setState({ cfgPressed: false });
|
2016-09-11 15:49:57 +03:00
|
|
|
});
|
2019-05-14 15:49:20 +03:00
|
|
|
this.setState({ cfgPressed: true });
|
2016-09-11 15:49:57 +03:00
|
|
|
ev.stopPropagation();
|
2018-12-02 19:27:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick = () =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
|
|
|
if (this.state.animating)
|
|
|
|
return;
|
|
|
|
this.setState({ animating: true, h: this.refs.vis.offsetHeight });
|
|
|
|
if (!this.state.collapsed)
|
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
setTimeout(() =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
this.setState({ h: 0 });
|
2016-09-11 15:49:57 +03:00
|
|
|
}, 50);
|
|
|
|
}
|
2019-05-14 15:49:20 +03:00
|
|
|
setTimeout(() =>
|
2016-09-11 15:49:57 +03:00
|
|
|
{
|
2019-05-14 15:49:20 +03:00
|
|
|
this.setState({ collapsed: !this.state.collapsed, animating: false, h: null });
|
2016-09-11 15:49:57 +03:00
|
|
|
}, this.state.collapsed ? 200 : 250);
|
|
|
|
}
|
2018-12-02 19:27:22 +03:00
|
|
|
}
|