summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-11 18:37:07 -0500
committerGitHub <noreply@github.com>2021-01-11 18:37:07 -0500
commit5e87a490f78888717c58491959745431580bd64e (patch)
tree59ae0b04fba8fe3005625f462ddcd8392f257da3 /ext/bg/js/anki.js
parent4ed949364564f00a8b871095d030af516fc2ed6d (diff)
Refactor display anki functions (#1224)
* Refactor note adding/viewing functions * Move _addDefinition * Update where anki field templates are assigned * Update _createNote to not include options/templates arguments * Simplify getAnkiNoteInfo to not require duplicateScope
Diffstat (limited to 'ext/bg/js/anki.js')
-rw-r--r--ext/bg/js/anki.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index ba5b4161..05c07ce2 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -103,12 +103,12 @@ class AnkiConnect {
return await this._invoke('storeMediaFile', {filename: fileName, data: dataBase64});
}
- async findNoteIds(notes, duplicateScope) {
+ async findNoteIds(notes) {
if (!this._enabled) { return []; }
await this._checkVersion();
const actions = notes.map((note) => {
let query = '';
- switch (duplicateScope) {
+ switch (this._getDuplicateScopeFromNote(note)) {
case 'deck':
query = `"deck:${this._escapeQuery(note.deckName)}" `;
break;
@@ -178,4 +178,15 @@ class AnkiConnect {
const key = fieldNames[0];
return `"${key.toLowerCase()}:${this._escapeQuery(fields[key])}"`;
}
+
+ _getDuplicateScopeFromNote(note) {
+ const {options} = note;
+ if (typeof options === 'object' && options !== null) {
+ const {duplicateScope} = options;
+ if (typeof duplicateScope !== 'undefined') {
+ return duplicateScope;
+ }
+ }
+ return null;
+ }
}