import React, { useState } from "react"; import CTAIconWrapper from "../components/globals/CTAIconWrapper"; import ChatItem from "../components/pages/ChatList/ChatItem"; import CTAModal from "../components/pages/ChatList/CTAModal"; import Menu from "../components/pages/ChatList/Menu"; import ChatListSkeleton from "../components/pages/ChatList/ChatListSkeleton"; import ActivePage from "../components/pages/Sidebar/ActivePage"; import useChatList from "../hooks/useChatList"; import { AnimatePresence, motion } from "framer-motion"; import ChatOptionsModal from "../components/pages/ChatList/ChatOptionsModal"; import { useDispatch, useSelector } from "react-redux"; import { modalActions } from "../store/modalSlice"; import Header from "../components/globals/Header"; import SearchBar from "../components/pages/ChatList/SearchBar"; import { useEffect } from "react"; import useSocket from "../hooks/useSocket"; import { chatListActions } from "../store/chatListSlice"; import { sidebarActions } from "../store/sidebarSlice"; function ChatList() { const { chatList, handleSearchValue, searchValue, loadingChatList } = useChatList(); const ctaModalVisible = useSelector( (state) => state.modalReducer.type === "ctaModal" ); const dispatch = useDispatch(); const { socketListen } = useSocket(); useEffect(() => { socketListen("user:chatRoomClear", ({ chatRoomId }) => { dispatch( chatListActions.removeFromChatList({ chatRoomId, }) ); }); }, []); return ( {loadingChatList === "loading" && } {loadingChatList === "success" && ( <>
{chatList.map((chatItem) => { if (!chatItem.latestMessage._id) return null; return ; })} {!chatList.length && (
)}
{/* CTA to create new group chat or private chat */} { if (ctaModalVisible) { dispatch(modalActions.closeModal()); } else { dispatch( modalActions.openModal({ positions: { right: 20, bottom: 80 }, type: "ctaModal", }) ); } }} > {!ctaModalVisible && ( )} {ctaModalVisible && ( )} )}
); } export default ChatList;