/** * @file components/sidebar/ChannelSidebar.tsx * @description Sidebar component for navigating text channels within an active server, featuring channel creation, editing, and mobile responsiveness. */ "use client"; import { useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { useActiveServer } from "@/lib/context/ServerContext"; import { DirectMessageSidebar } from "@/components/sidebar/DirectMessageSidebar"; import { useSidebarStore } from "@/lib/stores/useSidebarStore"; import { CreateChannelModal } from "@/components/modals/CreateChannelModal"; import { EditChannelModal } from "@/components/modals/EditChannelModal"; import { PanelLeftClose, Plus, Settings } from "lucide-react"; import type { Channel } from "@/db/schema"; /** * Renders the channel sidebar for the active server with text channel lists, creation triggers, and settings handlers. * * @returns {JSX.Element} The rendered channel sidebar container. */ export function ChannelSidebar() { const [isCreateModalOpen, setIsCreateModalOpen] = useState(false); const [editingChannel, setEditingChannel] = useState(null); const params = useParams(); const currentChannelId = params?.channelId as string; const { activeServer } = useActiveServer(); const { closeNav, toggleNav } = useSidebarStore(); /** * Handles channel selection clicks, automatically closing the mobile navigation drawer on smaller screens. * * @function handleChannelClick * @returns {void} */ const handleChannelClick = () => { if (!window.matchMedia("(min-width: 768px)").matches) { closeNav(); } }; /** * Opens the channel settings modal for the selected channel, preventing event propagation. * * @function handleOpenSettings * @param {React.MouseEvent} e - The mouse click event. * @param {Channel} channel - The channel object to edit. * @returns {void} */ const handleOpenSettings = (e: React.MouseEvent, channel: Channel) => { e.preventDefault(); e.stopPropagation(); setEditingChannel(channel); }; if (!activeServer) { return ; } return ( <>
{/* Server Header */}
{activeServer.name}
{/* Channel List */}
Text Channels
{activeServer.channels.map((channel) => { const isActive = currentChannelId === channel.id; return ( {/* Text Area */}
# {channel.name}
{/* Gear Button */} {!channel.isDefault && ( )} ); })}
{/* Modals */} setIsCreateModalOpen(false)} serverId={activeServer.id} /> setEditingChannel(null)} channel={editingChannel} /> ); }