Overview
TheChatApp component serves as the root container for the WhatsApp-style chat application. It manages the global chat state using Zustand, handles mobile/desktop layout switching, and coordinates communication between the sidebar and chat panel.
Usage
Features
- Responsive layout with mobile/desktop adaptation
- Global state management for chats, contacts, and messages
- Chat sorting by pinned status and last activity
- Auto-simulation of incoming messages via
useChatSimulatorhook - Empty state when no conversation is selected
Props
TheChatApp component takes no props. All state is managed internally via the useChatStore hook.
State management
The component consumes the following state from the chat store:Dictionary of all chat conversations indexed by chat ID
Dictionary of all contacts indexed by contact ID
Dictionary of all messages indexed by message ID
The ID of the currently active chat conversation
Draft messages for each chat, persisted across sessions
Array of active typing indicators showing who is currently typing
Layout behavior
Desktop layout
On desktop (viewport width >= 768px), both the sidebar and chat panel are visible side-by-side:- Sidebar: fixed width (max-w-sm)
- Chat panel: flexible width (flex-1)
Mobile layout
On mobile devices, the layout switches between views:- When no chat is selected: shows sidebar only
- When a chat is active: shows chat panel only with a back button
Chat sorting
Chats are automatically sorted by:- Pinned status - Pinned chats appear first
- Last activity - Most recent activity appears at the top
Empty state
When no conversation is selected, an empty state is displayed:Related components
- ChatSidebar - Displays the list of conversations
- ChatPanel - Displays the active conversation