From 008f38c0d27b53c89857b8e27b95c80f808b8c9b Mon Sep 17 00:00:00 2001 From: Maxim Dolgolyov Date: Tue, 2 Jun 2026 13:05:39 +0300 Subject: [PATCH] =?UTF-8?q?fix(flashcards):=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BD=D0=B0=D1=8F=20=D1=81=D0=B2=D1=8F=D0=B7=D1=8C=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - пустые поля -> тост-подсказка + фокус (раньше клик молчал) - ошибка POST показывается тостом (раньше глоталась .catch) Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/flashcards.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/flashcards.html b/frontend/flashcards.html index 8377a4e..9078d8c 100644 --- a/frontend/flashcards.html +++ b/frontend/flashcards.html @@ -802,14 +802,24 @@ async function persistCardOrder() { } async function addCard() { - if (!_curDeck) return; + if (!_curDeck) { LS.toast('Сначала откройте колоду', 'error'); return; } const front = document.getElementById('new-card-front').value.trim(); const back = document.getElementById('new-card-back').value.trim(); - if (!front && !back && !_newImg.front && !_newImg.back) return; - const card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, { - method: 'POST', - body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back }) - }).catch(()=>null); + if (!front && !back && !_newImg.front && !_newImg.back) { + LS.toast('Введите вопрос или ответ карточки'); + document.getElementById('new-card-front').focus(); + return; + } + let card; + try { + card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, { + method: 'POST', + body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back }) + }); + } catch (e) { + LS.toast('Не удалось добавить карточку: ' + (e && e.message || 'ошибка'), 'error'); + return; + } if (!card) return; _cards.push(card); document.getElementById('new-card-front').value = '';