import { memo, useCallback, useMemo, useState } from "react"; import {Link, useLocation, useParams} from "react-router-dom"; import {useRoomsQuery} from "@/hooks/useRoomsQuery"; import {useProjectInfo} from "@/hooks/useProjectInfo"; import {Hash, PanelLeftClose, Plus, Search, Settings} from "lucide-react"; import {CHANNEL_SIDEBAR} from "@/css/layout/styles"; import {ProjectCreateMenuModal} from "@/app/project"; const NAV_ITEMS = [ { path: "repos", name: "Repository", icon: "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z", }, { path: "issues", name: "Issues", icon: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4", }, { path: "skills", name: "Skills", icon: "M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z", }, { path: "board", name: "Board", icon: "M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z", }, { path: "chat", name: "Chat", icon: "M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z", }, ] as const; interface ChannelSidebarProps { onCollapse?: () => void; } export const ChannelSidebar = memo(function ChannelSidebar({onCollapse}: ChannelSidebarProps) { const location = useLocation(); const {projectName} = useParams<{ projectName: string }>(); const {data: projectInfo} = useProjectInfo(projectName); const isProjectMember = !!projectInfo?.role; const {data: roomsData, isLoading} = useRoomsQuery(isProjectMember ? projectName : undefined); const [isCreateMenuOpen, setIsCreateMenuOpen] = useState(false); const rooms = useMemo(() => roomsData?.rooms ?? [], [roomsData?.rooms]); const categories = useMemo(() => roomsData?.categories ?? [], [roomsData?.categories]); const pathParts = location.pathname.split("/").filter(Boolean); const isActive = useCallback((path: string) => { return pathParts.length >= 2 && pathParts[1] === path; }, [pathParts]); const isRoomActive = useCallback((roomId: string) => { return pathParts.length >= 3 && pathParts[2] === roomId; }, [pathParts]); const isSettingsActive = isActive("settings"); const showSettings = projectInfo?.role === "Owner" || projectInfo?.role === "Admin"; const uncategorizedRooms = useMemo( () => rooms.filter((r) => !r.isMuted && !r.category), [rooms], ); const categorizedRooms = useMemo( () => [...categories] .sort((a, b) => a.position - b.position) .map((cat) => ({ ...cat, rooms: rooms.filter((r) => !r.isMuted && r.category === cat.id), })) .filter((cat) => cat.rooms.length > 0), [rooms, categories], ); return (
{projectName || "Project"}
{isProjectMember && ( )} {onCollapse && ( )}
{isCreateMenuOpen && ( setIsCreateMenuOpen(false)}/> )}
); });