summaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-09 20:31:09 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-09 20:31:09 -0400
commit7ce54864f3fbaaeade2ebc20d80bcb084d9fa426 (patch)
treeb4b155a5e1b8d34222b4e2d612fd2c880926a54c /ext/bg/js/api.js
parent97f5b7139fcb69c68560d025f99418b0f697940c (diff)
Show the viewer button for anki notes which already exist
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 222e7ffe..ed7171b5 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -97,15 +97,33 @@ async function apiDefinitionsAddable(definitions, modes, optionsContext) {
}
}
- const results = await utilBackend().anki.canAddNotes(notes);
+ const cannotAdd = [];
+ const anki = utilBackend().anki;
+ const results = await anki.canAddNotes(notes);
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
- state[modes[modeOffset]] = results[resultBase + modeOffset];
+ const index = resultBase + modeOffset;
+ const result = results[index];
+ const info = {canAdd: result};
+ state[modes[modeOffset]] = info;
+ if (!result) {
+ cannotAdd.push([notes[index], info]);
+ }
}
states.push(state);
}
+
+ if (cannotAdd.length > 0) {
+ const noteIdsArray = await anki.findNoteIds(cannotAdd.map(e => e[0]));
+ for (let i = 0, ii = Math.min(cannotAdd.length, noteIdsArray.length); i < ii; ++i) {
+ const noteIds = noteIdsArray[i];
+ if (noteIds.length > 0) {
+ cannotAdd[i][1].noteId = noteIds[0];
+ }
+ }
+ }
} catch (e) {
// NOP
}