import { ChevronDown, Hash, Volume2 } from "lucide-react" import React from "react" import { NavLink } from "react-router" import { useShallow } from "zustand/react/shallow" import { ChannelType, type ServerChannel } from "~/lib/api/types" import { cn } from "~/lib/utils" import { useChannelsVoiceStateStore } from "~/stores/channels-voice-state" import { useGatewayStore } from "~/stores/gateway-store" import { useUsersStore } from "~/stores/users-store" import { Button } from "../ui/button" import UserAvatar from "../user-avatar" interface ChannelListItemProps { channel: ServerChannel } function ServerCategory({ channel }: ChannelListItemProps) { return (
{channel.name}
) } function ServerVoice({ channel }: ChannelListItemProps) { const updateVoiceState = useGatewayStore(state => state.updateVoiceState) const channelVoiceState = useChannelsVoiceStateStore(state => state.channels[channel.id]) || {} const userIds = Object.keys(channelVoiceState.users ?? {}) const { users, fetchUsersIfNotPresent } = useUsersStore(useShallow(state => ({ users: state.users, fetchUsersIfNotPresent: state.fetchUsersIfNotPresent }))) const channelUsers = React.useMemo(() => userIds.map(userId => users[userId]).filter(Boolean), [userIds, users]) React.useEffect(() => { fetchUsersIfNotPresent(userIds) }, [userIds]) const onClick = () => { updateVoiceState(channel.serverId, channel.id) } return ( <> {channelUsers.length > 0 &&
{ channelUsers .map(user => (
{user.displayName || user.username}
)) }
} ) } function ServerText({ channel }: ChannelListItemProps) { return ( {({ isActive }) => ( ) } ) } export default function ServerChannelListItem({ channel }: ChannelListItemProps) { switch (channel.type) { case ChannelType.SERVER_CATEGORY: return case ChannelType.SERVER_VOICE: return case ChannelType.SERVER_TEXT: return default: return null } }