dispatch/client/js/components/TabList.js

133 lines
3.5 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import classnames from 'classnames';
2019-01-27 07:53:07 +00:00
import get from 'lodash/get';
2020-04-29 01:10:13 +00:00
import { FiPlus, FiUser, FiSettings } from 'react-icons/fi';
import Button from 'components/ui/Button';
import TabListItem from 'containers/TabListItem';
2019-01-30 03:48:37 +00:00
import { count } from 'utils';
2015-12-28 23:34:32 +00:00
export default class TabList extends PureComponent {
2020-06-15 08:58:51 +00:00
handleTabClick = (network, target) => this.props.select(network, target);
2018-08-12 21:19:17 +00:00
handleConnectClick = () => this.props.push('/connect');
2018-08-12 21:19:17 +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,
2020-06-15 08:58:51 +00:00
networks,
2019-01-23 06:34:39 +00:00
privateChats,
showTabList,
openModal
} = this.props;
2015-12-28 23:34:32 +00:00
const tabs = [];
const className = classnames('tablist', {
'off-canvas': showTabList
});
2020-06-15 08:58:51 +00:00
channels.forEach(network => {
const { address } = network;
const srv = networks[address];
2015-12-28 23:34:32 +00:00
tabs.push(
<TabListItem
key={address}
2020-06-15 08:58:51 +00:00
network={address}
content={srv.name}
2020-06-15 08:58:51 +00:00
selected={tab.network === address && !tab.name}
connected={srv.connected}
2016-01-05 18:29:22 +00:00
onClick={this.handleTabClick}
2015-12-28 23:34:32 +00:00
/>
);
2020-06-15 08:58:51 +00:00
const chanCount = count(network.channels, c => c.joined);
2019-01-27 07:53:07 +00:00
const chanLimit =
get(srv.features, ['CHANLIMIT', '#'], 0) || srv.features.MAXCHANNELS;
2019-01-30 03:48:37 +00:00
let chanLabel;
2019-01-27 07:53:07 +00:00
if (chanLimit > 0) {
2019-01-30 03:48:37 +00:00
chanLabel = (
<span>
<span className="success">{chanCount}</span>/{chanLimit}
</span>
);
} else if (chanCount > 0) {
chanLabel = <span className="success">{chanCount}</span>;
2019-01-27 07:53:07 +00:00
}
2019-01-23 06:34:39 +00:00
tabs.push(
<div
key={`${address}-chans}`}
2020-06-19 02:38:26 +00:00
className="tab-label tab-label-channels"
2020-05-03 07:05:16 +00:00
onClick={() => openModal('channel', address)}
2019-01-23 06:34:39 +00:00
>
2019-01-30 03:48:37 +00:00
<span>CHANNELS {chanLabel}</span>
<Button title="Join Channel">+</Button>
2019-01-23 06:34:39 +00:00
</div>
);
2020-06-15 08:58:51 +00:00
network.channels.forEach(({ name, joined }) =>
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}
2020-06-15 08:58:51 +00:00
network={address}
2018-04-05 23:46:22 +00:00
target={name}
content={name}
2019-01-30 03:48:37 +00:00
joined={joined}
2020-06-15 08:58:51 +00:00
selected={tab.network === 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-30 03:48:37 +00:00
<span>
DIRECT MESSAGES{' '}
<span style={{ color: '#6bb758' }}>
{privateChats[address].length}
</span>
</span>
2019-02-08 08:10:06 +00:00
{/* <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}
2020-06-15 08:58:51 +00:00
network={address}
2018-04-25 03:36:27 +00:00
target={nick}
content={nick}
2020-06-15 08:58:51 +00:00
selected={tab.network === address && tab.name === nick}
2018-04-25 03:36:27 +00:00
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">
<Button
icon={FiPlus}
aria-label="Connect"
onClick={this.handleConnectClick}
/>
<Button icon={FiUser} aria-label="User" />
<Button
icon={FiSettings}
aria-label="Settings"
onClick={this.handleSettingsClick}
/>
2015-12-28 23:34:32 +00:00
</div>
</div>
);
}
}