import { useState } from 'react' import { Fragment } from 'react/jsx-runtime' import { format } from 'date-fns' import { IconArrowLeft, IconDotsVertical, IconEdit, IconMessages, IconPaperclip, IconPhone, IconPhotoPlus, IconPlus, IconSearch, IconSend, IconVideo, } from '@tabler/icons-react' import { cn } from '@/lib/utils' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { ScrollArea } from '@/components/ui/scroll-area' import { Separator } from '@/components/ui/separator' import { Button } from '@/components/button' import { Header } from '@/components/layout/header' import { Main } from '@/components/layout/main' import { ProfileDropdown } from '@/components/profile-dropdown' import { Search } from '@/components/search' import { ThemeSwitch } from '@/components/theme-switch' // Fake Data import { conversations } from './data/convo.json' type ChatUser = (typeof conversations)[number] type Convo = ChatUser['messages'][number] export default function Chats() { const [search, setSearch] = useState('') const [selectedUser, setSelectedUser] = useState(conversations[0]) const [mobileSelectedUser, setMobileSelectedUser] = useState( null ) // Filtered data based on the search query const filteredChatList = conversations.filter(({ fullName }) => fullName.toLowerCase().includes(search.trim().toLowerCase()) ) const currentMessage = selectedUser.messages.reduce( (acc: Record, obj) => { const key = format(obj.timestamp, 'd MMM, yyyy') // Create an array for the category if it doesn't exist if (!acc[key]) { acc[key] = [] } // Push the current object to the array acc[key].push(obj) return acc }, {} ) return ( <> {/* ===== Top Heading ===== */}
{/* Left Side */}

Inbox

{filteredChatList.map((chatUsr) => { const { id, profile, username, messages, fullName } = chatUsr const lastConvo = messages[0] const lastMsg = lastConvo.sender === 'You' ? `You: ${lastConvo.message}` : lastConvo.message return ( ) })}
{/* Right Side */}
) }