aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-05-21 18:55:02 +0200
committerGitHub <noreply@github.com>2024-05-21 16:55:02 +0000
commitba9fa339a43a5f494785877018b10f111ccafff5 (patch)
tree1a4a0b141e08cfe767170425d5afda253bf92990 /ext/js/background
parent737e7eab8182fc4e083f7fd6df840327ab83287c (diff)
add support for overwriting existing card (#859)
* frontend * wip * minimum viable * minor simplification * simplify gradients in duplicate svg * simplify add-duplicate svg * colors good * arrows shape * disable overwrite if no valid duplicate IDs * add warning
Diffstat (limited to 'ext/js/background')
-rw-r--r--ext/js/background/backend.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index dfb85e05..b9e23cbb 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -28,7 +28,7 @@ import {logErrorLevelToNumber} from '../core/log-utilities.js';
import {log} from '../core/log.js';
import {isObjectNotArray} from '../core/object-utilities.js';
import {clone, deferPromise, promiseTimeout} from '../core/utilities.js';
-import {invalidNoteId, isNoteDataValid} from '../data/anki-util.js';
+import {INVALID_NOTE_ID, isNoteDataValid} from '../data/anki-util.js';
import {arrayBufferToBase64} from '../data/array-buffer-util.js';
import {OptionsUtil} from '../data/options-util.js';
import {getAllPermissions, hasPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
@@ -153,6 +153,7 @@ export class Backend {
['getAnkiConnectVersion', this._onApiGetAnkiConnectVersion.bind(this)],
['isAnkiConnected', this._onApiIsAnkiConnected.bind(this)],
['addAnkiNote', this._onApiAddAnkiNote.bind(this)],
+ ['updateAnkiNote', this._onApiUpdateAnkiNote.bind(this)],
['getAnkiNoteInfo', this._onApiGetAnkiNoteInfo.bind(this)],
['injectAnkiNoteMedia', this._onApiInjectAnkiNoteMedia.bind(this)],
['viewNotes', this._onApiViewNotes.bind(this)],
@@ -539,6 +540,11 @@ export class Backend {
return await this._anki.addNote(note);
}
+ /** @type {import('api').ApiHandler<'updateAnkiNote'>} */
+ async _onApiUpdateAnkiNote({noteWithId}) {
+ return await this._anki.updateNoteFields(noteWithId);
+ }
+
/**
* @param {import('anki').Note[]} notes
* @returns {Promise<import('backend').CanAddResults>}
@@ -600,7 +606,7 @@ export class Backend {
const valid = isNoteDataValid(note);
if (isDuplicate && duplicateNoteIds[originalIndices.indexOf(i)].length === 0) {
- duplicateNoteIds[originalIndices.indexOf(i)] = [invalidNoteId];
+ duplicateNoteIds[originalIndices.indexOf(i)] = [INVALID_NOTE_ID];
}
const noteIds = isDuplicate ? duplicateNoteIds[originalIndices.indexOf(i)] : null;