feat(ui): срез 1.5 — инлайн-форма фидбека вместо prompt() (категория+текст, Esc, фокус)
This commit is contained in:
+47
-15
@@ -84,6 +84,14 @@ button { font-family: inherit; }
|
||||
:root[data-theme="dark"] .retry-btn { border-color: #ff8585; color: #ff8585; }
|
||||
.jump-latest { position: fixed; right: 24px; bottom: 100px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; font-size: 1.15rem; line-height: 1; display: none; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,.18); z-index: 50; }
|
||||
.jump-latest:hover { background: var(--bg-hover, var(--border)); }
|
||||
.fb-form { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; padding: .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); max-width: 360px; }
|
||||
.fb-cats { display: flex; gap: .4rem; }
|
||||
.fb-cat { flex: 1; font-size: .75rem; padding: .25rem; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
|
||||
.fb-cat.sel { border-color: #4c5b9a; background: rgba(76,91,154,.12); }
|
||||
.fb-text { font-size: .8rem; padding: .4rem; border: 1px solid var(--border); border-radius: 6px; resize: vertical; min-height: 48px; background: var(--bg); color: var(--text); font-family: inherit; }
|
||||
.fb-actions { display: flex; gap: .4rem; }
|
||||
.fb-send, .fb-cancel { font-size: .78rem; padding: .25rem .7rem; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--text); }
|
||||
.fb-send { background: #4c5b9a; color: #fff; border-color: transparent; }
|
||||
.msg-system { align-self: center; background: var(--system-bg); border: none; font-size: .8rem; color: var(--system-text); box-shadow: none; padding: .4rem .8rem; }
|
||||
.typing { align-self: flex-start; color: var(--text-light); font-style: italic; font-size: .85rem; padding: .4rem 0; }
|
||||
|
||||
@@ -729,21 +737,7 @@ function addMsg(type, text, ts) {
|
||||
const rep = document.createElement('button');
|
||||
rep.className = 'copy-btn report-btn';
|
||||
rep.textContent = 'Сообщить об ошибке';
|
||||
rep.onclick = async () => {
|
||||
const comment = prompt('Что не так с этим ответом? (можно оставить пустым)');
|
||||
if (comment === null) return; // отмена
|
||||
rep.disabled = true;
|
||||
try {
|
||||
const r = await authFetch('/api/feedback', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({comment: comment || '', answer: div._rawText || ''})
|
||||
});
|
||||
rep.textContent = r.ok ? 'Спасибо, отправлено' : 'Ошибка отправки';
|
||||
if (r.ok) rep.classList.add('copied');
|
||||
} catch (e) { rep.textContent = 'Ошибка отправки'; }
|
||||
setTimeout(() => { rep.textContent = 'Сообщить об ошибке'; rep.classList.remove('copied'); rep.disabled = false; }, 2200);
|
||||
};
|
||||
rep.onclick = () => openFeedbackForm(rep, div._rawText || '');
|
||||
div.appendChild(rep);
|
||||
}
|
||||
msgs.appendChild(div);
|
||||
@@ -934,6 +928,44 @@ function addErrorRetry(msg, retryText) {
|
||||
div.appendChild(btn);
|
||||
}
|
||||
|
||||
// Инлайн-форма фидбека вместо prompt(): категория + текст, Esc закрывает, фокус в поле.
|
||||
function openFeedbackForm(btn, answerText) {
|
||||
if (btn._fbOpen) return;
|
||||
btn._fbOpen = true;
|
||||
const form = document.createElement('div');
|
||||
form.className = 'fb-form';
|
||||
form.innerHTML =
|
||||
'<div class="fb-cats">' +
|
||||
'<button type="button" class="fb-cat" data-c="Ответ неверный">Ответ неверный</button>' +
|
||||
'<button type="button" class="fb-cat" data-c="Другое">Другое</button></div>' +
|
||||
'<textarea class="fb-text" placeholder="Что не так? (можно кратко)" aria-label="Комментарий"></textarea>' +
|
||||
'<div class="fb-actions"><button type="button" class="fb-send">Отправить</button>' +
|
||||
'<button type="button" class="fb-cancel">Отмена</button></div>';
|
||||
btn.after(form);
|
||||
const ta = form.querySelector('.fb-text');
|
||||
let cat = '';
|
||||
form.querySelectorAll('.fb-cat').forEach(c => c.onclick = () => {
|
||||
form.querySelectorAll('.fb-cat').forEach(x => x.classList.remove('sel'));
|
||||
c.classList.add('sel'); cat = c.dataset.c; ta.focus();
|
||||
});
|
||||
const close = () => { form.remove(); btn._fbOpen = false; };
|
||||
form.querySelector('.fb-cancel').onclick = close;
|
||||
ta.addEventListener('keydown', e => { if (e.key === 'Escape') close(); });
|
||||
form.querySelector('.fb-send').onclick = async () => {
|
||||
const comment = (cat ? cat + ': ' : '') + ta.value.trim();
|
||||
try {
|
||||
const r = await authFetch('/api/feedback', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({comment: comment, answer: answerText})});
|
||||
close();
|
||||
btn.textContent = r.ok ? 'Спасибо, отправлено' : 'Ошибка отправки';
|
||||
if (r.ok) btn.classList.add('copied');
|
||||
} catch (e) { close(); btn.textContent = 'Ошибка отправки'; }
|
||||
setTimeout(() => { btn.textContent = 'Сообщить об ошибке'; btn.classList.remove('copied'); }, 2200);
|
||||
};
|
||||
ta.focus();
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
if (streaming) return;
|
||||
const input = document.getElementById('msg-input');
|
||||
|
||||
Reference in New Issue
Block a user