/* eslint-disable complexity */ "use client"; import { motion, MotionConfig } from "framer-motion"; import { MdChevronRight } from "react-icons/md"; import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext"; import { cn, isToday, isWithinLast30Days, isWithinLast7Days, isYesterday } from "@/lib/utils"; import { ChatsListItem } from "./components/ChatsListItem"; import { MiniFooter } from "./components/ChatsListItem/components/MiniFooter"; import { NewChatButton } from "./components/NewChatButton"; import { useChatsList } from "./hooks/useChatsList"; import { useSelectedChatPage } from "../../[chatId]/hooks/useSelectedChatPage"; export const ChatsList = (): JSX.Element => { const { allChats } = useChatsContext(); const { open, setOpen } = useChatsList(); useSelectedChatPage(); // Filtering chats into different groups const todayChats = allChats.filter(chat => isToday(new Date(chat.creation_time))); const yesterdayChats = allChats.filter(chat => isYesterday(new Date(chat.creation_time))); const last7DaysChats = allChats.filter(chat => isWithinLast7Days(new Date(chat.creation_time))); const last30DaysChats = allChats.filter(chat => isWithinLast30Days(new Date(chat.creation_time))); return ( { if (info.offset.x > 100 && !open) { setOpen(true); } else if (info.offset.x < -100 && open) { setOpen(false); } }} 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" >
{todayChats.length > 0 &&
Today
} {todayChats.map((chat) => ( ))} {yesterdayChats.length > 0 &&
Yesterday
} {yesterdayChats.map((chat) => ( ))} {last7DaysChats.length > 0 &&
Previous 7 Days
} {last7DaysChats.map((chat) => ( ))} {last30DaysChats.length > 0 &&
Previous 30 Days
} {last30DaysChats.map((chat) => ( ))}
); };