Spaces:
Build error
Build error
Upload components/ChatList.js with huggingface_hub
Browse files- components/ChatList.js +103 -0
components/ChatList.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { User, Users, Plus, Search, Lock } from 'lucide-react';
|
| 2 |
+
import { useState } from 'react';
|
| 3 |
+
|
| 4 |
+
export default function ChatList({ chats, activeChatId, onSelectChat, onCreateGroup }) {
|
| 5 |
+
const [searchTerm, setSearchTerm] = useState('');
|
| 6 |
+
const [showCreateModal, setShowCreateModal] = useState(false);
|
| 7 |
+
|
| 8 |
+
const filteredChats = chats.filter(chat =>
|
| 9 |
+
chat.name.toLowerCase().includes(searchTerm.toLowerCase())
|
| 10 |
+
);
|
| 11 |
+
|
| 12 |
+
return (
|
| 13 |
+
<div className="w-full md:w-80 lg:w-96 bg-telegram-sidebar flex flex-col border-r border-gray-800 h-full">
|
| 14 |
+
{/* Search & Actions */}
|
| 15 |
+
<div className="p-3 space-y-3">
|
| 16 |
+
<div className="relative">
|
| 17 |
+
<Search className="absolute left-3 top-2.5 text-telegram-secondary" size={18} />
|
| 18 |
+
<input
|
| 19 |
+
type="text"
|
| 20 |
+
placeholder="Search"
|
| 21 |
+
className="w-full bg-telegram-bg text-telegram-text pl-10 pr-4 py-2 rounded-full text-sm focus:outline-none focus:ring-1 focus:ring-telegram-accent placeholder-gray-500"
|
| 22 |
+
value={searchTerm}
|
| 23 |
+
onChange={(e) => setSearchTerm(e.target.value)}
|
| 24 |
+
/>
|
| 25 |
+
</div>
|
| 26 |
+
<button
|
| 27 |
+
onClick={() => setShowCreateModal(true)}
|
| 28 |
+
className="w-full bg-telegram-accent hover:bg-blue-600 text-white py-2 rounded-full text-sm font-medium transition-colors flex items-center justify-center gap-2"
|
| 29 |
+
>
|
| 30 |
+
<Plus size={16} /> New Chat or Group
|
| 31 |
+
</button>
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
{/* Chat List */}
|
| 35 |
+
<div className="flex-1 overflow-y-auto">
|
| 36 |
+
{filteredChats.map((chat) => (
|
| 37 |
+
<div
|
| 38 |
+
key={chat.id}
|
| 39 |
+
onClick={() => onSelectChat(chat.id)}
|
| 40 |
+
className={`flex items-center gap-3 p-3 cursor-pointer transition-colors hover:bg-white/5 ${activeChatId === chat.id ? 'bg-white/10' : ''}`}
|
| 41 |
+
>
|
| 42 |
+
<div className={`w-12 h-12 rounded-full flex items-center justify-center text-lg font-bold ${chat.isGroup ? 'bg-purple-600' : 'bg-gradient-to-br from-blue-500 to-cyan-400'}`}>
|
| 43 |
+
{chat.isGroup ? <Users size={24} /> : chat.name.charAt(0)}
|
| 44 |
+
</div>
|
| 45 |
+
<div className="flex-1 min-w-0">
|
| 46 |
+
<div className="flex justify-between items-center mb-1">
|
| 47 |
+
<h3 className="font-medium truncate">{chat.name}</h3>
|
| 48 |
+
<span className="text-xs text-telegram-secondary">{chat.lastTime}</span>
|
| 49 |
+
</div>
|
| 50 |
+
<div className="flex justify-between items-center">
|
| 51 |
+
<p className="text-sm text-telegram-secondary truncate flex items-center gap-1">
|
| 52 |
+
{chat.encrypted && <Lock size={10} className="text-green-500" />}
|
| 53 |
+
{chat.lastMessage}
|
| 54 |
+
</p>
|
| 55 |
+
{chat.unread > 0 && (
|
| 56 |
+
<span className="bg-telegram-accent text-white text-xs font-bold px-2 py-0.5 rounded-full min-w-[20px] text-center">
|
| 57 |
+
{chat.unread}
|
| 58 |
+
</span>
|
| 59 |
+
)}
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
))}
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
{/* Create Group Modal (Simple Implementation) */}
|
| 67 |
+
{showCreateModal && (
|
| 68 |
+
<div className="absolute inset-0 bg-black/80 z-50 flex items-center justify-center p-4">
|
| 69 |
+
<div className="bg-telegram-sidebar w-full max-w-sm rounded-xl p-6 border border-gray-700">
|
| 70 |
+
<h2 className="text-xl font-bold mb-4">New Group</h2>
|
| 71 |
+
<p className="text-telegram-secondary text-sm mb-4">
|
| 72 |
+
Create a secure group for up to 20 people. All messages are end-to-end encrypted.
|
| 73 |
+
</p>
|
| 74 |
+
<div className="flex gap-2 mb-4">
|
| 75 |
+
<input
|
| 76 |
+
type="text"
|
| 77 |
+
placeholder="Group Name"
|
| 78 |
+
className="flex-1 bg-telegram-bg border border-gray-700 rounded-lg px-3 py-2 focus:outline-none focus:border-telegram-accent"
|
| 79 |
+
/>
|
| 80 |
+
</div>
|
| 81 |
+
<div className="flex justify-end gap-2">
|
| 82 |
+
<button
|
| 83 |
+
onClick={() => setShowCreateModal(false)}
|
| 84 |
+
className="px-4 py-2 text-sm text-telegram-secondary hover:text-white"
|
| 85 |
+
>
|
| 86 |
+
Cancel
|
| 87 |
+
</button>
|
| 88 |
+
<button
|
| 89 |
+
onClick={() => {
|
| 90 |
+
onCreateGroup();
|
| 91 |
+
setShowCreateModal(false);
|
| 92 |
+
|
| 93 |
+
className="px-4 py-2 bg-telegram-accent text-white rounded-lg text-sm font-medium"
|
| 94 |
+
>
|
| 95 |
+
Create
|
| 96 |
+
</button>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
)}
|
| 101 |
+
</div>
|
| 102 |
+
);
|
| 103 |
+
}
|