"use client"; import { useState } from "react"; import { useSidebarStore } from "@/lib/stores/sidebar-store"; import { ChatSectionHeader } from "./ChatSectionHeader"; import { ChatListRow } from "./ChatListRow"; import { usePathname } from "next/navigation"; import { cn } from "@/lib/utils"; export interface ChatMessageListProps { channelId?: string; } export function ChatMessageList({ channelId }: ChatMessageListProps = {}) { const pathname = usePathname(); const isChatRoute = pathname.startsWith("/") && pathname.includes("/chat/"); if (!isChatRoute) return null; const [searchQuery, setSearchQuery] = useState(""); const [filter, setFilter] = useState(""); const [expandedSections, setExpandedSections] = useState({ favorites: true, channels: true, dms: true, }); const { favorites, channels, dms } = useSidebarStore((state) => ({ favorites: state.favorites, channels: state.channels, dms: state.dms, })); const toggleSection = (section: "favorites" | "channels" | "dms") => setExpandedSections((prev) => ({ ...prev, [section]: !prev[section], })); // Filter items based on search query const filterItems = (items: any[], query: string) => { if (!query) return items; return items.filter( (item) => item.label.toLowerCase().includes(query.toLowerCase()) || item.preview?.toLowerCase().includes(query.toLowerCase()) ); }; const filteredFavorites = filterItems(favorites, searchQuery); const filteredChannels = filterItems(channels, searchQuery); const filteredDms = filterItems(dms, searchQuery); return (

{channelId ? "Channel Messages" : "Recent Chats"}

setSearchQuery(e.target.value)} className="w-full p-2 border border-sidebar-rounded bg-background" />
{/* Favorites Section */} toggleSection("favorites")} onAdd={() => console.log("Add to favorites")} onMore={() => console.log("More options for favorites")} /> {expandedSections.favorites && (
{filteredFavorites.map((item) => ( ))}
)} {/* Channels Section */} toggleSection("channels")} onAdd={() => console.log("Add channel")} onMore={() => console.log("More options for channels")} /> {expandedSections.channels && (
{filteredChannels.map((item) => ( ))}
)} {/* DMs Section */} toggleSection("dms")} onAdd={() => console.log("Add DM")} onMore={() => console.log("More options for DMs")} /> {expandedSections.dms && (
{filteredDms.map((item) => ( ))}
)}
); }