2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-11 00:59:16 +03:00
|
|
|
"use client";
|
2023-06-15 12:52:46 +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 { useState } from "react";
|
|
|
|
import { MdChevronRight } from "react-icons/md";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-11 00:59:16 +03:00
|
|
|
import ChatsListItem from "./ChatsListItem";
|
|
|
|
import { NewChatButton } from "./NewChatButton";
|
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-14 23:58:37 +03:00
|
|
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
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 }}
|
|
|
|
// dragSnapToOrigin
|
|
|
|
dragElastic={0.15}
|
|
|
|
onDragEnd={(event, info) => {
|
|
|
|
if (info.offset.x > 100 && !open) {
|
|
|
|
setOpen(true);
|
|
|
|
} else if (info.offset.x < -100 && open) {
|
|
|
|
setOpen(false);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="lg:sticky fixed top-0 left-0 bottom-0 overflow-visible z-30 border-r border-black/10 dark:border-white/25 bg-white dark:bg-black"
|
|
|
|
>
|
|
|
|
<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)",
|
|
|
|
// shadow: open ? "none" : "10px 10px 16px black",
|
|
|
|
}}
|
|
|
|
className={cn("overflow-hidden")}
|
|
|
|
>
|
|
|
|
<div className="min-w-fit max-h-screen overflow-auto scrollbar">
|
|
|
|
<aside className="relative max-w-xs w-full h-screen">
|
|
|
|
<NewChatButton />
|
|
|
|
<div className="flex flex-col gap-0">
|
|
|
|
{allChats.map((chat) => (
|
|
|
|
<ChatsListItem
|
|
|
|
key={chat.chatId}
|
|
|
|
chat={chat}
|
|
|
|
deleteChat={deleteChat}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
</motion.div>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setOpen(!open);
|
|
|
|
}}
|
|
|
|
className="absolute left-full top-16 lg:top-0 text-3xl bg-black dark:bg-white text-white dark:text-black rounded-r-full p-3 pl-1"
|
|
|
|
>
|
|
|
|
<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
|
|
|
};
|