refactor(chat): decompose core.js into scroll.js, messages.js, input.js, and core.js

This commit is contained in:
2026-10-27 15:23:45 +03:00
parent d4a248dc33
commit 676437a958
8 changed files with 385 additions and 392 deletions
+7 -68
View File
@@ -119,20 +119,12 @@ window.TopicsManager = (function() {
</div>
</div>
</div>
<div class="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition shrink-0 mt-0.5">
<button type="button"
onclick="event.stopPropagation(); window.TopicsManager.openRenameModal('${session.id}', '${escapeHtml(title)}')"
class="p-1 text-slate-400 hover:text-indigo-600 rounded transition"
title="Переименовать тему">
<i class="fa-solid fa-pencil text-xs"></i>
</button>
<button type="button"
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
class="p-1 text-slate-400 hover:text-rose-600 rounded transition"
title="Удалить чат">
<i class="fa-solid fa-trash-can text-xs"></i>
</button>
</div>
<button type="button"
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
class="opacity-0 group-hover:opacity-100 p-1 text-slate-400 hover:text-rose-600 rounded transition shrink-0"
title="Удалить чат">
<i class="fa-solid fa-trash-can text-xs"></i>
</button>
</div>
`;
}).join("");
@@ -283,65 +275,12 @@ window.TopicsManager = (function() {
}
});
function openRenameModal(sessionId, currentTitle) {
const modal = document.getElementById("rename-topic-modal");
const idInput = document.getElementById("rename-topic-session-id");
const titleInput = document.getElementById("rename-topic-input");
if (idInput) idInput.value = sessionId;
if (titleInput) {
titleInput.value = currentTitle;
setTimeout(() => {
titleInput.focus();
titleInput.select();
}, 50);
}
if (modal) modal.classList.remove("hidden");
}
function closeRenameModal() {
const modal = document.getElementById("rename-topic-modal");
if (modal) modal.classList.add("hidden");
}
async function submitRenameModal(event) {
if (event) event.preventDefault();
const sessionId = document.getElementById("rename-topic-session-id")?.value;
const newTitle = document.getElementById("rename-topic-input")?.value.trim();
if (!sessionId || !newTitle) return;
closeRenameModal();
try {
const res = await fetch('/api/v1/chat/sessions/' + encodeURIComponent(sessionId), {
method: 'PATCH',
headers: {
...AuthManager.getAuthHeaders(),
'Content-Type': 'application/json'
},
body: JSON.stringify({ title: newTitle })
});
if (res.ok) {
await loadTopics();
} else {
console.error("Ошибка сохранения названия темы");
}
} catch (e) {
console.error("Ошибка сети при переименовании темы:", e);
}
}
return {
init,
loadTopics,
getActiveSessionId,
switchTopic,
createNewTopic,
askDeleteTopic,
openRenameModal,
closeRenameModal,
submitRenameModal
askDeleteTopic
};
})();