2017-02-17 00:46:39 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-06-03 04:18:03 +00:00
|
|
|
import classnames from 'classnames';
|
2019-01-27 07:53:07 +00:00
|
|
|
import get from 'lodash/get';
|
2018-11-04 06:22:46 +00:00
|
|
|
import Button from 'components/ui/Button';
|
2019-01-25 10:02:31 +00:00
|
|
|
import TabListItem from 'containers/TabListItem';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2017-02-17 00:46:39 +00:00
|
|
|
export default class TabList extends PureComponent {
|
2017-05-07 20:19:15 +00:00
|
|
|
handleTabClick = (server, target) => this.props.select(server, target);
|
2018-08-12 21:19:17 +00:00
|
|
|
|
2017-05-27 05:30:22 +00:00
|
|
|
handleConnectClick = () => this.props.push('/connect');
|
2018-08-12 21:19:17 +00:00
|
|
|
|
2017-05-27 05:30:22 +00:00
|
|
|
handleSettingsClick = () => this.props.push('/settings');
|
2015-12-28 23:34:32 +00:00
|
|
|
|
|
|
|
render() {
|
2019-01-23 06:34:39 +00:00
|
|
|
const {
|
|
|
|
tab,
|
|
|
|
channels,
|
|
|
|
servers,
|
|
|
|
privateChats,
|
|
|
|
showTabList,
|
|
|
|
openModal
|
|
|
|
} = this.props;
|
2015-12-28 23:34:32 +00:00
|
|
|
const tabs = [];
|
|
|
|
|
2018-06-03 04:18:03 +00:00
|
|
|
const className = classnames('tablist', {
|
|
|
|
'off-canvas': showTabList
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
channels.forEach(server => {
|
|
|
|
const { address } = server;
|
|
|
|
const srv = servers[address];
|
2015-12-28 23:34:32 +00:00
|
|
|
tabs.push(
|
|
|
|
<TabListItem
|
|
|
|
key={address}
|
2016-01-05 18:29:22 +00:00
|
|
|
server={address}
|
2017-07-02 01:31:00 +00:00
|
|
|
content={srv.name}
|
2018-04-25 03:36:27 +00:00
|
|
|
selected={tab.server === address && !tab.name}
|
2017-07-02 01:31:00 +00:00
|
|
|
connected={srv.status.connected}
|
2016-01-05 18:29:22 +00:00
|
|
|
onClick={this.handleTabClick}
|
2015-12-28 23:34:32 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2019-01-27 07:53:07 +00:00
|
|
|
let chanLabel;
|
|
|
|
const chanLimit =
|
|
|
|
get(srv.features, ['CHANLIMIT', '#'], 0) || srv.features.MAXCHANNELS;
|
|
|
|
if (chanLimit > 0) {
|
|
|
|
chanLabel = `CHANNELS (${server.channels.length}/${chanLimit})`;
|
|
|
|
} else {
|
|
|
|
chanLabel = `CHANNELS (${server.channels.length})`;
|
|
|
|
}
|
|
|
|
|
2019-01-23 06:34:39 +00:00
|
|
|
tabs.push(
|
|
|
|
<div
|
|
|
|
key={`${address}-chans}`}
|
|
|
|
className="tab-label"
|
|
|
|
onClick={() => openModal('channel', { server: address })}
|
|
|
|
>
|
2019-01-27 07:53:07 +00:00
|
|
|
<span>{chanLabel}</span>
|
2019-01-23 06:34:39 +00:00
|
|
|
<Button>+</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
server.channels.forEach(name =>
|
2018-04-05 23:46:22 +00:00
|
|
|
tabs.push(
|
2016-01-05 18:29:22 +00:00
|
|
|
<TabListItem
|
2018-04-05 23:46:22 +00:00
|
|
|
key={address + name}
|
2016-01-05 18:29:22 +00:00
|
|
|
server={address}
|
2018-04-05 23:46:22 +00:00
|
|
|
target={name}
|
|
|
|
content={name}
|
|
|
|
selected={tab.server === address && tab.name === name}
|
2016-01-05 18:29:22 +00:00
|
|
|
onClick={this.handleTabClick}
|
|
|
|
/>
|
2018-04-05 23:46:22 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
if (privateChats[address] && privateChats[address].length > 0) {
|
2018-04-05 23:46:22 +00:00
|
|
|
tabs.push(
|
|
|
|
<div key={`${address}-pm}`} className="tab-label">
|
2019-01-23 06:34:39 +00:00
|
|
|
<span>DIRECT MESSAGES ({privateChats[address].length})</span>
|
|
|
|
{/*<Button>+</Button>*/}
|
2018-04-05 23:46:22 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
privateChats[address].forEach(nick =>
|
|
|
|
tabs.push(
|
|
|
|
<TabListItem
|
|
|
|
key={address + nick}
|
|
|
|
server={address}
|
|
|
|
target={nick}
|
|
|
|
content={nick}
|
|
|
|
selected={tab.server === address && tab.name === nick}
|
|
|
|
onClick={this.handleTabClick}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
2015-12-28 23:34:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
|
|
|
<div className="tab-container">{tabs}</div>
|
|
|
|
<div className="side-buttons">
|
2018-11-04 06:22:46 +00:00
|
|
|
<Button onClick={this.handleConnectClick}>+</Button>
|
2017-02-16 02:55:50 +00:00
|
|
|
<i className="icon-user" />
|
|
|
|
<i className="icon-cog" onClick={this.handleSettingsClick} />
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|