2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-11 00:59:16 +03:00
|
|
|
"use client";
|
2023-07-03 19:38:12 +03:00
|
|
|
import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext";
|
2023-06-14 23:58:37 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import { MotionConfig, motion } from "framer-motion";
|
|
|
|
import { MdChevronRight } from "react-icons/md";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-07-03 18:39:59 +03:00
|
|
|
import { ChatsListItem } from "./components/ChatsListItem";
|
2023-06-27 12:28:09 +03:00
|
|
|
import { MiniFooter } from "./components/ChatsListItem/components/MiniFooter";
|
2023-07-03 18:39:59 +03:00
|
|
|
import { NewChatButton } from "./components/NewChatButton";
|
2023-06-27 12:28:09 +03:00
|
|
|
import { useChatsList } from "./hooks/useChatsList";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
|
|
|
export const ChatsList = (): JSX.Element => {
|
2023-06-11 15:34:36 +03:00
|
|
|
const { allChats, deleteChat } = useChatsContext();
|
2023-06-27 12:28:09 +03:00
|
|
|
const { open, setOpen } = useChatsList();
|
2023-06-11 00:59:16 +03:00
|
|
|
return (
|
2023-06-14 23:58:37 +03:00
|
|
|
<MotionConfig transition={{ mass: 1, damping: 10 }}>
|
|
|
|
<motion.div
|
|
|
|
drag="x"
|
|
|
|
dragConstraints={{ right: 0, left: 0 }}
|
|
|
|
dragElastic={0.15}
|
|
|
|
onDragEnd={(event, info) => {
|
|
|
|
if (info.offset.x > 100 && !open) {
|
|
|
|
setOpen(true);
|
|
|
|
} else if (info.offset.x < -100 && open) {
|
|
|
|
setOpen(false);
|
|
|
|
}
|
|
|
|
}}
|
2023-07-02 15:30:11 +03:00
|
|
|
className="flex flex-col lg:sticky fixed top-16 left-0 bottom-0 lg:h-[90vh] overflow-visible z-30 border-r border-black/10 dark:border-white/25 bg-white dark:bg-black"
|
2023-06-14 23:58:37 +03:00
|
|
|
>
|
|
|
|
<motion.div
|
|
|
|
animate={{
|
|
|
|
width: open ? "fit-content" : "0px",
|
|
|
|
opacity: open ? 1 : 0.5,
|
|
|
|
boxShadow: open
|
|
|
|
? "10px 10px 16px rgba(0, 0, 0, 0)"
|
|
|
|
: "10px 10px 16px rgba(0, 0, 0, 0.5)",
|
|
|
|
}}
|
2023-07-02 15:30:11 +03:00
|
|
|
className={cn("overflow-hidden flex flex-col flex-1")}
|
2023-07-03 19:38:12 +03:00
|
|
|
data-testid="chats-list"
|
2023-06-14 23:58:37 +03:00
|
|
|
>
|
2023-07-02 15:30:11 +03:00
|
|
|
<div className="flex flex-col flex-1">
|
2023-06-27 12:28:09 +03:00
|
|
|
<NewChatButton />
|
2023-07-03 19:38:12 +03:00
|
|
|
<div
|
|
|
|
data-testid="chats-list-items"
|
|
|
|
className="flex-1 overflow-auto scrollbar h-full"
|
|
|
|
>
|
2023-06-27 12:28:09 +03:00
|
|
|
{allChats.map((chat) => (
|
|
|
|
<ChatsListItem
|
|
|
|
key={chat.chat_id}
|
|
|
|
chat={chat}
|
|
|
|
deleteChat={deleteChat}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<MiniFooter />
|
2023-06-14 23:58:37 +03:00
|
|
|
</div>
|
|
|
|
</motion.div>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setOpen(!open);
|
|
|
|
}}
|
2023-06-27 12:28:09 +03:00
|
|
|
className="absolute left-full top-16 text-3xl bg-black dark:bg-white text-white dark:text-black rounded-r-full p-3 pl-1"
|
2023-07-03 19:38:12 +03:00
|
|
|
data-testid="chats-list-toggle"
|
2023-06-14 23:58:37 +03:00
|
|
|
>
|
|
|
|
<motion.div
|
|
|
|
whileTap={{ scale: 0.9 }}
|
|
|
|
animate={{ scaleX: open ? -1 : 1 }}
|
|
|
|
>
|
|
|
|
<MdChevronRight />
|
|
|
|
</motion.div>
|
|
|
|
</button>
|
|
|
|
</motion.div>
|
|
|
|
</MotionConfig>
|
2023-06-11 00:59:16 +03:00
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|