From 970071a3515b75d9010e56d5681543947fc91799 Mon Sep 17 00:00:00 2001 From: anor Date: Tue, 9 Jun 2026 14:23:36 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BB=D0=B5=D0=B2=D0=B0=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BB=D1=8C=20=D1=81=D0=BE=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=BE=D0=BC=20=D1=87=D0=B0=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20(=D0=BA=D0=B0=D0=BA=20=D0=B2=20=D0=B4=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=BF=D0=BD=D0=BE=D0=BC=20=D0=9A=D0=BB=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Постоянная панель слева: список диалогов (превью+дата), переключение, кнопка «+ Новый чат», подсветка активного. На мобиле — выезжающая шторка с ☰. Бэкенд не тронут (/api/sessions, /api/history уже были). --- static/chat.html | 113 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 98 insertions(+), 15 deletions(-) diff --git a/static/chat.html b/static/chat.html index d432a4e..0dd3604 100644 --- a/static/chat.html +++ b/static/chat.html @@ -97,6 +97,29 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo #send-btn:disabled { background: #d4c5b2; cursor: not-allowed; } #file-btn { padding: .65rem .7rem; background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 1.1rem; transition: all .15s; } #file-btn:hover { border-color: var(--accent); background: var(--accent-light); } + +/* Layout with left chat sidebar (Claude-desktop style) */ +.app-layout { flex: 1; display: flex; min-height: 0; } +.sidebar { width: 264px; flex-shrink: 0; background: var(--bg-card); border-right: 1px solid var(--border); display: flex; flex-direction: column; } +.sidebar-head { padding: .7rem; border-bottom: 1px solid var(--border-light); } +.new-chat-btn { width: 100%; padding: .6rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: .85rem; font-weight: 600; cursor: pointer; transition: background .15s; } +.new-chat-btn:hover { background: var(--accent-hover); } +.chat-list { flex: 1; overflow-y: auto; padding: .4rem; } +.chat-list-empty { padding: 1rem .7rem; color: var(--text-muted); font-size: .78rem; text-align: center; } +.chat-item { padding: .5rem .65rem; border-radius: 8px; cursor: pointer; margin-bottom: .15rem; border: 1px solid transparent; transition: background .12s; } +.chat-item:hover { background: var(--bg); } +.chat-item.active { background: var(--accent-light); border-color: var(--border); } +.ci-title { font-size: .82rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.ci-date { font-size: .66rem; color: var(--text-muted); margin-top: .12rem; } +.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; } +#sidebar-toggle { display: none; padding: .35rem .6rem; background: transparent; border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: .95rem; color: var(--text-muted); margin-right: .5rem; } +.sidebar-backdrop { display: none; } +@media (max-width: 720px) { + .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-md); } + .sidebar.open { transform: translateX(0); } + #sidebar-toggle { display: inline-block; } + .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 55; } +} @@ -116,8 +139,20 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo @@ -219,6 +255,7 @@ function showChat() { document.getElementById('chat-screen').style.display = 'flex'; document.getElementById('msg-input').focus(); loadHistory(); + loadSessions(); } // --- Auth --- @@ -571,16 +608,30 @@ async function sendMessage() { streaming = false; document.getElementById('send-btn').disabled = false; input.focus(); + loadSessions(); // обновить превью/порядок чатов в панели } } // --- Session --- -async function resetSession() { - // Create new tab = new session, old one stays in DB +async function newChat() { + // New tab = new session, old one stays in DB and in the sidebar + closeSidebar(); tabId = genUUID(); localStorage.setItem('tabId', tabId); msgs.innerHTML = ''; addMsg('system', 'Новый диалог начат.'); + renderSessions(); + document.getElementById('msg-input').focus(); +} + +function toggleSidebar() { + const sb = document.getElementById('sidebar'); + const open = sb.classList.toggle('open'); + document.getElementById('sidebar-backdrop').classList.toggle('show', open); +} +function closeSidebar() { + document.getElementById('sidebar').classList.remove('open'); + document.getElementById('sidebar-backdrop').classList.remove('show'); } async function listFiles() { @@ -624,21 +675,53 @@ async function loadHistory() { } catch {} } -async function showSessions() { +// --- Chat sidebar (Claude-desktop style left panel) --- +let allSessions = []; +async function loadSessions() { try { const r = await fetch(API + '/api/sessions', {headers: authHeaders()}); if (!r.ok) return; - const sessions = await r.json(); - if (sessions.length === 0) { addMsg('system', 'Нет сохранённых диалогов.'); return; } - let text = 'Прошлые диалоги:\n\n'; - sessions.forEach((s, i) => { - const date = new Date(s.last_ts * 1000).toLocaleString('ru'); - const preview = (s.last_question || '').slice(0, 60); - text += (i + 1) + '. ' + date + ' (' + s.msg_count + ' сообщ.) — ' + preview + '\n'; - }); - addMsg('system', text); + allSessions = await r.json(); + renderSessions(); } catch {} } +function renderSessions() { + const list = document.getElementById('chat-list'); + if (!list) return; + list.innerHTML = ''; + // Текущий ещё не сохранённый диалог (без сообщений) — показываем сверху активным + if (!allSessions.some(s => s.tab_id === tabId)) { + list.appendChild(makeChatItem({tab_id: tabId, last_question: 'Новый чат', last_ts: null}, true)); + } + for (const s of allSessions) list.appendChild(makeChatItem(s, s.tab_id === tabId)); + if (!list.children.length) list.innerHTML = '
Пока нет чатов
'; +} +function makeChatItem(s, active) { + const div = document.createElement('div'); + div.className = 'chat-item' + (active ? ' active' : ''); + div.onclick = () => switchChat(s.tab_id); + const t = document.createElement('div'); + t.className = 'ci-title'; + t.textContent = (s.last_question || 'Без названия').slice(0, 90) || 'Новый чат'; + div.appendChild(t); + if (s.last_ts) { + const d = document.createElement('div'); + d.className = 'ci-date'; + d.textContent = new Date(s.last_ts * 1000).toLocaleString('ru-RU', + {day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit'}); + div.appendChild(d); + } + return div; +} +async function switchChat(id) { + closeSidebar(); + if (id === tabId) return; + tabId = id; + localStorage.setItem('tabId', tabId); + msgs.innerHTML = ''; + await loadHistory(); + renderSessions(); +} // Auto-resize textarea document.getElementById('msg-input').addEventListener('input', function() {