import { useEffect, useState } from "react"; import { useAuthStore } from "../store/authStore"; import { useChatStore } from "../store/chatStore"; import { NewChatPanel } from "./NewChatPanel"; export function ChatList() { const chats = useChatStore((s) => s.chats); const messagesByChat = useChatStore((s) => s.messagesByChat); const activeChatId = useChatStore((s) => s.activeChatId); const setActiveChatId = useChatStore((s) => s.setActiveChatId); const loadChats = useChatStore((s) => s.loadChats); const me = useAuthStore((s) => s.me); const [search, setSearch] = useState(""); const [tab, setTab] = useState<"all" | "people" | "groups" | "channels">("all"); useEffect(() => { const timer = setTimeout(() => { void loadChats(search.trim() ? search : undefined); }, 250); return () => clearTimeout(timer); }, [search, loadChats]); const filteredChats = chats.filter((chat) => { if (tab === "people") { return chat.type === "private"; } if (tab === "groups") { return chat.type === "group"; } if (tab === "channels") { return chat.type === "channel"; } return true; }); const tabs: Array<{ id: "all" | "people" | "groups" | "channels"; label: string }> = [ { id: "all", label: "All" }, { id: "people", label: "Люди" }, { id: "groups", label: "Groups" }, { id: "channels", label: "Каналы" } ]; return ( ); }