fix(feedback): show server error on fbSubmit, disable button during request
This commit is contained in:
+34
-2
@@ -570,6 +570,19 @@
|
|||||||
document.getElementById('fbPromptClose').addEventListener('click', closePromptModal);
|
document.getElementById('fbPromptClose').addEventListener('click', closePromptModal);
|
||||||
document.getElementById('fbPromptModal').addEventListener('click', e => { if (e.target.id === 'fbPromptModal') closePromptModal(); });
|
document.getElementById('fbPromptModal').addEventListener('click', e => { if (e.target.id === 'fbPromptModal') closePromptModal(); });
|
||||||
document.getElementById('fbPromptText').addEventListener('input', updatePromptCount);
|
document.getElementById('fbPromptText').addEventListener('input', updatePromptCount);
|
||||||
|
document.getElementById('fbPromptKeys').addEventListener('click', e => {
|
||||||
|
const key = e.target.closest('.fb-key');
|
||||||
|
const ta = document.getElementById('fbPromptText');
|
||||||
|
const code = key && key.querySelector('code');
|
||||||
|
if (!ta || !code) return;
|
||||||
|
const token = code.textContent.trim();
|
||||||
|
const start = ta.selectionStart ?? ta.value.length;
|
||||||
|
const end = ta.selectionEnd ?? start;
|
||||||
|
ta.value = ta.value.slice(0, start) + token + ta.value.slice(end);
|
||||||
|
ta.focus();
|
||||||
|
ta.setSelectionRange(start + token.length, start + token.length);
|
||||||
|
updatePromptCount();
|
||||||
|
});
|
||||||
document.getElementById('fbPromptReset').addEventListener('click', () => {
|
document.getElementById('fbPromptReset').addEventListener('click', () => {
|
||||||
document.getElementById('fbPromptText').value = '';
|
document.getElementById('fbPromptText').value = '';
|
||||||
document.getElementById('fbDefaultModel').value = '';
|
document.getElementById('fbDefaultModel').value = '';
|
||||||
@@ -605,10 +618,29 @@
|
|||||||
body.short_message_ids = shortIds;
|
body.short_message_ids = shortIds;
|
||||||
const url = id ? `${API}/api/feedbacks/${id}` : `${API}/api/feedbacks`;
|
const url = id ? `${API}/api/feedbacks/${id}` : `${API}/api/feedbacks`;
|
||||||
const method = id ? 'PUT' : 'POST';
|
const method = id ? 'PUT' : 'POST';
|
||||||
|
const btn = document.getElementById('fbSubmit');
|
||||||
|
const prev = btn ? btn.textContent : '';
|
||||||
try {
|
try {
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = id ? 'Сохранение...' : 'Отправка...';
|
||||||
|
}
|
||||||
const r = await fetch(url, { method, headers: {...hdr(), 'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
const r = await fetch(url, { method, headers: {...hdr(), 'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||||
if (r.ok) { closeModal(); loadFeedbacks(); }
|
if (r.ok) {
|
||||||
} catch (e) {}
|
closeModal();
|
||||||
|
loadFeedbacks();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const err = await r.json().catch(() => null);
|
||||||
|
alert((err && err.error) || `Ошибка ${r.status}`);
|
||||||
|
} catch (e) {
|
||||||
|
alert('Ошибка сети');
|
||||||
|
} finally {
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.textContent = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
document.getElementById('fbResident').addEventListener('input', () => {
|
document.getElementById('fbResident').addEventListener('input', () => {
|
||||||
clearTimeout(shortsFetchTimer);
|
clearTimeout(shortsFetchTimer);
|
||||||
|
|||||||
Reference in New Issue
Block a user