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 = '