import { useState } from 'react' import { Fragment } from 'react/jsx-runtime' import { format } from 'date-fns' import { ArrowLeft, MoreVertical, Edit, Paperclip, Phone, ImagePlus, Plus, Search as SearchIcon, Send, Video, MessagesSquare, } from 'lucide-react' import { cn } from '@/lib/utils' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Button } from '@/components/ui/button' import { ScrollArea } from '@/components/ui/scroll-area' import { Separator } from '@/components/ui/separator' import { ConfigDrawer } from '@/components/config-drawer' 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' import { NewChat } from './components/new-chat' import { type ChatUser, type Convo } from './data/chat-types' // Fake Data import { conversations } from './data/convo.json' export function Chats() { const [search, setSearch] = useState('') const [selectedUser, setSelectedUser] = useState(null) const [mobileSelectedUser, setMobileSelectedUser] = useState( null ) const [createConversationDialogOpened, setCreateConversationDialog] = useState(false) // 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 }, {} ) const users = conversations.map(({ messages, ...user }) => user) 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 */} {selectedUser ? ( ) : ( )}
) }