aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-10 16:05:17 -0400
committerGitHub <noreply@github.com>2020-09-10 16:05:17 -0400
commit892f7ed3b8d4a97dd7fd8086a404c5e8ea1355fb (patch)
treeccc4551b2dbef20193c85a946e61d8774873cad2 /ext/mixed/js/display.js
parent3dd4822ab3e1312336065f70cf31b87dac39473b (diff)
Anki note api functions (#802)
* Assign duplicateScope to a variable * Add api.addAnkiNote * Add api.getAnkiNoteInfo, update returned data format
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 6fdab46b..7dd5920a 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -889,10 +889,15 @@ class Display extends EventDispatcher {
async _setContentTermsOrKanjiUpdateAdderButtons(token, isTerms, definitions) {
const modes = isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
- const states = await this._getDefinitionsAddable(definitions, modes);
+ let states;
+ try {
+ states = await this._getDefinitionsAddable(definitions, modes);
+ } catch (e) {
+ return;
+ }
if (this._setContentToken !== token) { return; }
- this._updateAdderButtons(states);
+ this._updateAdderButtons(states, modes);
}
_setContentExtensionUnloaded() {
@@ -953,19 +958,22 @@ class Display extends EventDispatcher {
this._navigationHeader.dataset.hasNext = `${!!next}`;
}
- _updateAdderButtons(states) {
- for (let i = 0; i < states.length; ++i) {
+ _updateAdderButtons(states, modes) {
+ for (let i = 0, ii = states.length; i < ii; ++i) {
+ const infos = states[i];
let noteId = null;
- for (const [mode, info] of Object.entries(states[i])) {
+ for (let j = 0, jj = infos.length; j < jj; ++j) {
+ const {canAdd, noteIds} = infos[j];
+ const mode = modes[j];
const button = this._adderButtonFind(i, mode);
if (button === null) {
continue;
}
- if (!info.canAdd && noteId === null && info.noteId) {
- noteId = info.noteId;
+ if (Array.isArray(noteIds) && noteIds.length > 0) {
+ noteId = noteIds[0];
}
- button.classList.toggle('disabled', !info.canAdd);
+ button.classList.toggle('disabled', !canAdd);
button.classList.remove('pending');
}
if (noteId !== null) {