fix(flashcards): обратная связь при добавлении карточки
- пустые поля -> тост-подсказка + фокус (раньше клик молчал) - ошибка POST показывается тостом (раньше глоталась .catch) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -802,14 +802,24 @@ async function persistCardOrder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addCard() {
|
async function addCard() {
|
||||||
if (!_curDeck) return;
|
if (!_curDeck) { LS.toast('Сначала откройте колоду', 'error'); return; }
|
||||||
const front = document.getElementById('new-card-front').value.trim();
|
const front = document.getElementById('new-card-front').value.trim();
|
||||||
const back = document.getElementById('new-card-back').value.trim();
|
const back = document.getElementById('new-card-back').value.trim();
|
||||||
if (!front && !back && !_newImg.front && !_newImg.back) return;
|
if (!front && !back && !_newImg.front && !_newImg.back) {
|
||||||
const card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, {
|
LS.toast('Введите вопрос или ответ карточки');
|
||||||
|
document.getElementById('new-card-front').focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let card;
|
||||||
|
try {
|
||||||
|
card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back })
|
body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back })
|
||||||
}).catch(()=>null);
|
});
|
||||||
|
} catch (e) {
|
||||||
|
LS.toast('Не удалось добавить карточку: ' + (e && e.message || 'ошибка'), 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
_cards.push(card);
|
_cards.push(card);
|
||||||
document.getElementById('new-card-front').value = '';
|
document.getElementById('new-card-front').value = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user