feat: левая панель со списком чатов (как в десктопном Клоде)
Постоянная панель слева: список диалогов (превью+дата), переключение, кнопка «+ Новый чат», подсветка активного. На мобиле — выезжающая шторка с ☰. Бэкенд не тронут (/api/sessions, /api/history уже были).
This commit is contained in:
+98
-15
@@ -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; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -116,8 +139,20 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo
|
||||
|
||||
<!-- Chat Screen -->
|
||||
<div id="chat-screen" style="display:none">
|
||||
<div class="sidebar-backdrop" id="sidebar-backdrop" onclick="closeSidebar()"></div>
|
||||
<div class="app-layout">
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<button class="new-chat-btn" onclick="newChat()">+ Новый чат</button>
|
||||
</div>
|
||||
<div class="chat-list" id="chat-list"></div>
|
||||
</aside>
|
||||
<div class="main-col">
|
||||
<div id="header">
|
||||
<h1>Сметный ИИ-ассистент</h1>
|
||||
<div style="display:flex;align-items:center">
|
||||
<button id="sidebar-toggle" onclick="toggleSidebar()" title="Чаты">☰</button>
|
||||
<h1>Сметный ИИ-ассистент</h1>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button id="btn-admin" style="display:none" onclick="window.open('/admin','_blank')">Админ</button>
|
||||
<!-- Депрекированы 2026-05-07 (этап 5 — депрекация отдельных страниц).
|
||||
@@ -130,8 +165,7 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo
|
||||
<button onclick="window.open('/reference','_blank')">Справочники</button>
|
||||
<button onclick="window.open('/check','_blank')">Проверка</button>
|
||||
-->
|
||||
<button onclick="showSessions()">История</button>
|
||||
<button onclick="resetSession()">Новый диалог</button>
|
||||
<button onclick="newChat()">Новый диалог</button>
|
||||
<button onclick="listFiles()">Файлы</button>
|
||||
<button onclick="logout()">Выйти</button>
|
||||
</div>
|
||||
@@ -151,6 +185,8 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo
|
||||
<input type="file" id="file-input" multiple hidden onchange="handleFiles(this.files)">
|
||||
<div style="text-align:center;margin-top:4px"><a href="/static/security.html" target="_blank" style="font-size:.65rem;color:var(--text-muted);opacity:.4;text-decoration:none">О безопасности сервиса</a></div>
|
||||
</div>
|
||||
</div><!-- /.main-col -->
|
||||
</div><!-- /.app-layout -->
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
@@ -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 = '<div class="chat-list-empty">Пока нет чатов</div>';
|
||||
}
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user