aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/anki-templates-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-03 11:30:48 -0400
committerGitHub <noreply@github.com>2021-07-03 11:30:48 -0400
commitf7d177e6d0f970ba6600fbf3911fccc093553eef (patch)
treed83865cb66308f98b57bea7d9e1ca172c257e049 /ext/js/pages/settings/anki-templates-controller.js
parentd7c934cae8c4f0747a0298b7e237ebab4efd48e5 (diff)
Refactor createNote (#1789)
* Update createNote to return a wrapper object * Update how createNote creates errors
Diffstat (limited to 'ext/js/pages/settings/anki-templates-controller.js')
-rw-r--r--ext/js/pages/settings/anki-templates-controller.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js
index 9502a2fd..aa565bad 100644
--- a/ext/js/pages/settings/anki-templates-controller.js
+++ b/ext/js/pages/settings/anki-templates-controller.js
@@ -147,8 +147,8 @@ class AnkiTemplatesController {
}
async _validate(infoNode, field, mode, showSuccessResult, invalidateInput) {
+ const allErrors = [];
const text = this._renderTextInput.value || '';
- const errors = [];
let result = `No definition found for ${text}`;
try {
const optionsContext = this._settingsController.getOptionsContext();
@@ -168,7 +168,7 @@ class AnkiTemplatesController {
let template = options.anki.fieldTemplates;
if (typeof template !== 'string') { template = this._defaultFieldTemplates; }
const {general: {resultOutputMode, glossaryLayoutMode, compactTags}} = options;
- const note = await this._ankiNoteBuilder.createNote({
+ const {note, errors} = await this._ankiNoteBuilder.createNote({
dictionaryEntry,
mode,
context,
@@ -180,13 +180,13 @@ class AnkiTemplatesController {
],
resultOutputMode,
glossaryLayoutMode,
- compactTags,
- errors
+ compactTags
});
result = note.fields.field;
+ allErrors.push(...errors);
}
} catch (e) {
- errors.push(e);
+ allErrors.push(e);
}
const errorToMessageString = (e) => {
@@ -205,9 +205,9 @@ class AnkiTemplatesController {
return `${e}`;
};
- const hasError = errors.length > 0;
+ const hasError = allErrors.length > 0;
infoNode.hidden = !(showSuccessResult || hasError);
- infoNode.textContent = hasError ? errors.map(errorToMessageString).join('\n') : (showSuccessResult ? result : '');
+ infoNode.textContent = hasError ? allErrors.map(errorToMessageString).join('\n') : (showSuccessResult ? result : '');
infoNode.classList.toggle('text-danger', hasError);
if (invalidateInput) {
this._fieldTemplatesTextarea.dataset.invalid = `${hasError}`;