import React from 'react'; import { useServerStore } from '../../stores/serverStore'; import { useChatStore } from '../../stores/chatStore'; import { useUIStore } from '../../stores/uiStore'; import { useAuthStore } from '../../stores/authStore'; import { MessageList } from '../chat/MessageList'; import { MessageInput } from '../chat/MessageInput'; import { TypingIndicator } from '../chat/TypingIndicator'; import { VoiceGrid } from '../voice/VoiceGrid'; import { FriendsPage } from '../chat/FriendsPage'; import { Avatar } from '../ui/Avatar'; import { useVoiceStore } from '../../stores/voiceStore'; import { wsSend } from '../../hooks/useWebSocket'; export function MainContent() { const channels = useServerStore((s) => s.channels); const currentChannelId = useChatStore((s) => s.currentChannelId); const currentServerId = useServerStore((s) => s.currentServerId); const toggleMemberList = useUIStore((s) => s.toggleMemberList); const memberListOpen = useUIStore((s) => s.memberListOpen); const participants = useVoiceStore((s) => s.participants); const currentVoiceChannelId = useVoiceStore((s) => s.currentVoiceChannelId); const showDms = useUIStore((s) => s.showDms); const channel = channels.find(c => c.id === currentChannelId); const isVoiceChannel = channel?.type === 'voice' || channel?.type === 'video'; // DM view or no server selected const dmChannels = useServerStore((s) => s.dmChannels); const authUser = useAuthStore((s) => s.user); if (showDms || !currentServerId) { if (!currentChannelId) { return ; } const dmChannel = dmChannels.find(dm => dm.id === currentChannelId); const otherUser = dmChannel?.members.find(m => m.id !== authUser?.id); const dmName = otherUser?.displayName ?? otherUser?.username ?? 'Direct Message'; const dmStatus = otherUser?.status as any; return (
@ {otherUser && ( )} {dmName} {otherUser?.status && otherUser.status !== 'offline' && ( {otherUser.status} )}
); } // No channel selected if (!currentChannelId || !channel) { return (
Select a channel

Select a text or voice channel to get started

); } // Voice/Video channel view if (isVoiceChannel) { const isInThisChannel = currentVoiceChannelId === currentChannelId; const isMuted = useVoiceStore.getState().isMuted; const isCameraOn = useVoiceStore.getState().isCameraOn; const isScreenSharing = useVoiceStore.getState().isScreenSharing; return (
{channel.name} {isInThisChannel && ( Connected )}
{isInThisChannel ? ( ) : (

{channel.name}

No one is currently in this voice channel.

)}
); } // Text channel view return (
{/* Channel header */}
{channel.name} {channel.topic && ( <>
{channel.topic} )}
{/* Messages */} {/* Typing indicator */} {/* Message input */}
); }