docbrown/app/javascript/chat/channels.jsx
Ben Halpern 4171a0814a
Add basic alpha DM functionality to chat (#375)
* Initial chat DM features

* Update functionality for DM chats
2018-06-01 16:21:48 -04:00

42 lines
1.3 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
const Channels = ({ activeChannelId, chatChannels, handleSwitchChannel }) => {
const channels = chatChannels.map(channel => {
const otherClassname =
parseInt(activeChannelId, 10) === channel.id
? 'chatchanneltab--active'
: 'chatchanneltab--inactive';
const name = channel.channel_type === "direct" ? '@'+channel.slug.replace(`${window.currentUser.username}/`, '').replace(`/${window.currentUser.username}`, '') : channel.channel_name
return (
<button
className='chatchanneltabbutton'
onClick={handleSwitchChannel}
data-channel-id={channel.id}
data-channel-name={name}
>
<span className={`chatchanneltab ${otherClassname}`}
onClick={handleSwitchChannel}
data-channel-id={channel.id}
data-channel-name={name}
>
{name}
</span>
</button>
);
});
return (
<div className="chatchannels">
<div className="chatchannels__channelslist">{channels}</div>
</div>
);
};
Channels.propTypes = {
activeChannelId: PropTypes.number.isRequired,
chatChannels: PropTypes.array.isRequired,
handleSwitchChannel: PropTypes.func.isRequired,
};
export default Channels;