diff --git a/static/css/live_chat.css b/static/css/live_chat.css index 0b884ea..1c88c4d 100644 --- a/static/css/live_chat.css +++ b/static/css/live_chat.css @@ -292,4 +292,32 @@ html { .send-btn-telegram:active { transform: scale(0.95); +} + +/* ── Users Modal Solid Backgrounds ── */ +#users-modal { + background-color: #f8fafc !important; +} + +#users-modal > div:nth-child(2) { + background-color: #ffffff !important; + border-bottom: 1px solid #e5e7eb !important; +} + +#users-list { + background-color: #f8fafc !important; +} + +/* Dark Mode Support */ +.dark #users-modal { + background-color: #1f2937 !important; +} + +.dark #users-modal > div:nth-child(2) { + background-color: #111827 !important; + border-bottom: 1px solid #374151 !important; +} + +.dark #users-list { + background-color: #1f2937 !important; } \ No newline at end of file diff --git a/static/js/live_chat.js b/static/js/live_chat.js index 069eb51..bb87e4e 100644 --- a/static/js/live_chat.js +++ b/static/js/live_chat.js @@ -1,15 +1,11 @@ document.addEventListener('DOMContentLoaded', function () { - // متغیرهای وضعیت let currentRoomId = null; let lastMessageId = 0; let messagePollInterval = null; let roomPollInterval = null; - - // 🟢 متغیر قفل برای جلوگیری از دریافت پیامهای تکراری (Race Condition) let isFetchingMessages = false; - // المانهای DOM const UI = { roomList: document.getElementById('room-list'), noChatSelected: document.getElementById('no-chat-selected'), @@ -19,21 +15,119 @@ document.addEventListener('DOMContentLoaded', function () { inputArea: document.getElementById('chat-input-area'), form: document.getElementById('chat-form'), input: document.getElementById('chat-input'), - indicator: document.getElementById('polling-indicator') + indicator: document.getElementById('polling-indicator'), + + // 🟢 متغیرهای جدید برای Modal کاربران + newChatBtn: document.getElementById('new-chat-btn'), + usersModal: document.getElementById('users-modal'), + closeModalBtn: document.getElementById('close-users-modal'), + usersList: document.getElementById('users-list'), + searchInput: document.getElementById('user-search-input') + }; + + // ── منطق مودال کاربران ── + if (UI.newChatBtn) { + UI.newChatBtn.addEventListener('click', () => { + UI.usersModal.style.transform = 'translateY(0)'; // نمایش مودال (بالا آمدن) + fetchUsers(''); // لود اولیه لیست کاربران + }); + } + + if (UI.closeModalBtn) { + UI.closeModalBtn.addEventListener('click', () => { + UI.usersModal.style.transform = 'translateY(100%)'; // مخفی کردن مودال (پایین رفتن) + }); + } + + if (UI.searchInput) { + let timeout = null; + UI.searchInput.addEventListener('input', (e) => { + clearTimeout(timeout); + // دیباونس (Debounce) برای جلوگیری از ریکوئستهای تکراری + timeout = setTimeout(() => { + fetchUsers(e.target.value); + }, 300); + }); + } + + async function fetchUsers(query) { + UI.usersList.innerHTML = '
Failed to load users.
'; + } + } + + function renderUsers(users) { + if (users.length === 0) { + UI.usersList.innerHTML = 'No users found.
'; + return; + } + + UI.usersList.innerHTML = users.map(user => { + const initial = user.name ? user.name.charAt(0).toUpperCase() : 'U'; + + // استفاده از کلاسهای room-item و room-avatar برای هماهنگی 100 درصدی + return ` +No active chats found.
'; @@ -43,27 +137,35 @@ document.addEventListener('DOMContentLoaded', function () { UI.roomList.innerHTML = rooms.map(room => { const isActive = currentRoomId === room.id; const safeTitle = room.title.replace(/'/g, "\\'"); + const initial = room.title ? room.title.charAt(0).toUpperCase() : 'G'; + return `No messages yet. Say hi!
-No messages yet. Start the conversation!