fix(flashcards): обратная связь при добавлении карточки

- пустые поля -> тост-подсказка + фокус (раньше клик молчал)
- ошибка POST показывается тостом (раньше глоталась .catch)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-06-02 13:05:39 +03:00
parent 3d627ce782
commit 008f38c0d2
+16 -6
View File
@@ -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 = '';