aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-06 18:16:51 -0500
committerGitHub <noreply@github.com>2021-01-06 18:16:51 -0500
commit3760b22a2544d0f86a8097b345831de8efc0e325 (patch)
treed669362f3b9b4d2d17e27ef55e80ed3700f0bb9a /ext/bg
parent8c92c1cbc246001e27a1e31e53c2ce992bf72fbd (diff)
Fix AnkiCardController using stale data (#1204)
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/settings/anki-controller.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js
index 96d43b7a..4fba77a6 100644
--- a/ext/bg/js/settings/anki-controller.js
+++ b/ext/bg/js/settings/anki-controller.js
@@ -41,7 +41,6 @@ class AnkiController {
'clipboard-text'
]);
this._stringComparer = new Intl.Collator(); // Locale does not matter
- this._ankiOptions = null;
this._getAnkiDataPromise = null;
this._ankiErrorContainer = null;
this._ankiErrorMessageNode = null;
@@ -174,7 +173,6 @@ class AnkiController {
// Private
async _onOptionsChanged({options: {anki}}) {
- this._ankiOptions = anki;
this._ankiConnect.server = anki.server;
this._ankiConnect.enabled = anki.enable;
@@ -188,7 +186,7 @@ class AnkiController {
}
_onAnkiEnableChanged({detail: {value}}) {
- if (this._ankiOptions === null) { return; }
+ if (this._ankiConnect.server === null) { return; }
this._ankiConnect.enabled = value;
for (const cardController of this._selectorObserver.datas()) {
@@ -215,7 +213,7 @@ class AnkiController {
_createCardController(node) {
const cardController = new AnkiCardController(this._settingsController, this, node);
- cardController.prepare(this._ankiOptions);
+ cardController.prepare();
return cardController;
}
@@ -383,9 +381,14 @@ class AnkiCardController {
this._ankiCardDeckSelect = null;
this._ankiCardModelSelect = null;
this._ankiCardFieldsContainer = null;
+ this._cleaned = false;
}
- async prepare(ankiOptions) {
+ async prepare() {
+ const options = await this._settingsController.getOptions();
+ const ankiOptions = options.anki;
+ if (this._cleaned) { return; }
+
const cardOptions = this._getCardOptions(ankiOptions, this._cardType);
if (cardOptions === null) { return; }
const {deck, model, fields} = cardOptions;
@@ -407,12 +410,14 @@ class AnkiCardController {
}
cleanup() {
+ this._cleaned = true;
this._eventListeners.removeAllEventListeners();
}
async updateAnkiState() {
if (this._fields === null) { return; }
const {deckNames, modelNames} = await this._ankiController.getAnkiData();
+ if (this._cleaned) { return; }
this._setupSelects(deckNames, modelNames);
}