import { h } from 'preact';
import PropTypes from 'prop-types';
import { ChannelButton } from './components/ChannelButton';
import { ConfigMenu } from './configMenu';
import { channelSorter } from './util';
export const Channels = ({
activeChannelId,
chatChannels,
unopenedChannelIds,
handleSwitchChannel,
expanded,
filterQuery = '',
channelsLoaded,
currentUserId,
triggerActiveContent,
}) => {
const sortedChatChannels = channelSorter(
chatChannels,
currentUserId,
filterQuery,
);
const discoverableChannels = sortedChatChannels.discoverableChannels.map(
(channel) => {
return (
);
},
);
const channels = sortedChatChannels.activeChannels.map((channel) => {
const isActive = parseInt(activeChannelId, 10) === channel.chat_channel_id;
const isUnopened =
!isActive && unopenedChannelIds.includes(channel.chat_channel_id);
const newMessagesIndicator = isUnopened ? 'new' : 'old';
const otherClassname = isActive
? 'chatchanneltab--active'
: 'chatchanneltab--inactive';
return (
);
});
let topNotice = '';
if (
expanded &&
filterQuery.length === 0 &&
channelsLoaded &&
(channels.length === 0 || channels[0].messages_count === 0)
) {
topNotice = (
👋
{' '}
Welcome to
Connect! You may message anyone you mutually follow.
);
}
let channelsListFooter = '';
if (channels.length === 30) {
channelsListFooter = (
...
);
}
return (
{topNotice}
{channels}
{discoverableChannels.length > 0 && filterQuery.length > 0 ? (
Global Channel Search
{discoverableChannels}
) : (
''
)}
{channelsListFooter}
);
};
Channels.propTypes = {
activeChannelId: PropTypes.number.isRequired,
chatChannels: PropTypes.arrayOf(PropTypes.objectOf()).isRequired,
unopenedChannelIds: PropTypes.arrayOf().isRequired,
handleSwitchChannel: PropTypes.func.isRequired,
triggerActiveContent: PropTypes.func.isRequired,
expanded: PropTypes.bool.isRequired,
filterQuery: PropTypes.string.isRequired,
channelsLoaded: PropTypes.bool.isRequired,
currentUserId: PropTypes.string.isRequired,
};