summaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-04-22 21:58:32 +0200
committerGitHub <noreply@github.com>2024-04-22 19:58:32 +0000
commitc6d93a965a5536979221fda856903356c10c1603 (patch)
tree7511f7c3b432f00e704c62f8eaefc19c252b9dc4 /ext/js/display
parent808ddef82a8eabc77ba20a0da89a392926550e76 (diff)
add duplicate behavior dropdown (#853)
* duplicate behavior dropdown * allow duplicate for existing users * Update docs/anki-integration.md Co-authored-by: James Maa <jmaa@berkeley.edu> Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com> * Update docs/anki-integration.md Co-authored-by: James Maa <jmaa@berkeley.edu> Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com> * Update docs/anki-integration.md Co-authored-by: James Maa <jmaa@berkeley.edu> Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com> * remove suggestion comment --------- Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com> Co-authored-by: James Maa <jmaa@berkeley.edu>
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/display-anki.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js
index 446b8b48..23f7157f 100644
--- a/ext/js/display/display-anki.js
+++ b/ext/js/display/display-anki.js
@@ -74,6 +74,8 @@ export class DisplayAnki {
this._duplicateScope = 'collection';
/** @type {boolean} */
this._duplicateScopeCheckAllModels = false;
+ /** @type {import('settings').AnkiDuplicateBehavior} */
+ this._duplicateBehavior = 'prevent';
/** @type {import('settings').AnkiScreenshotFormat} */
this._screenshotFormat = 'png';
/** @type {number} */
@@ -192,6 +194,7 @@ export class DisplayAnki {
tags,
duplicateScope,
duplicateScopeCheckAllModels,
+ duplicateBehavior,
suspendNewCards,
checkForDuplicates,
displayTags,
@@ -212,6 +215,7 @@ export class DisplayAnki {
this._displayTags = displayTags;
this._duplicateScope = duplicateScope;
this._duplicateScopeCheckAllModels = duplicateScopeCheckAllModels;
+ this._duplicateBehavior = duplicateBehavior;
this._screenshotFormat = format;
this._screenshotQuality = quality;
this._scanLength = scanLength;
@@ -419,7 +423,7 @@ export class DisplayAnki {
// If entry has noteIds, show the "add duplicate" button.
if (Array.isArray(noteIds) && noteIds.length > 0) {
- this._showDuplicateAddButton(button);
+ this._updateButtonForDuplicate(button);
}
}
@@ -442,6 +446,17 @@ export class DisplayAnki {
}
/**
+ * @param {HTMLButtonElement} button
+ */
+ _updateButtonForDuplicate(button) {
+ if (this._duplicateBehavior === 'prevent') {
+ button.disabled = true;
+ } else {
+ this._showDuplicateAddButton(button);
+ }
+ }
+
+ /**
* @param {number} i
* @param {(?import('anki').NoteInfo)[]} noteInfos
*/
@@ -550,7 +565,7 @@ export class DisplayAnki {
}
}
// Now that this dictionary entry has a duplicate in Anki, show the "add duplicate" buttons.
- this._showDuplicateAddButton(button);
+ this._updateButtonForDuplicate(button);
this._updateViewNoteButton(dictionaryEntryIndex, [noteId], true);
}