aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/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/mixed/js
parent97f5b7139fcb69c68560d025f99418b0f697940c (diff)
Show the viewer button for anki notes which already exist
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/display.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 9beb2c52..17370654 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -286,15 +286,23 @@ class Display {
for (let i = 0; i < states.length; ++i) {
const state = states[i];
+ let noteId = null;
for (const mode in state) {
const button = this.adderButtonFind(i, mode);
if (button === null) {
continue;
}
- button.classList.toggle('disabled', !state[mode]);
+ const info = state[mode];
+ if (!info.canAdd && noteId === null && info.noteId) {
+ noteId = info.noteId;
+ }
+ button.classList.toggle('disabled', !info.canAdd);
button.classList.remove('pending');
}
+ if (noteId !== null) {
+ this.viewerButtonShow(i, noteId);
+ }
}
} catch (e) {
this.onError(e);
@@ -380,11 +388,7 @@ class Display {
if (adderButton !== null) {
adderButton.classList.add('disabled');
}
- const viewerButton = this.viewerButtonFind(index);
- if (viewerButton !== null) {
- viewerButton.classList.remove('pending', 'disabled');
- viewerButton.dataset.noteId = noteId;
- }
+ this.viewerButtonShow(index, noteId);
} else {
throw new Error('Note could not be added');
}
@@ -504,6 +508,15 @@ class Display {
return entry !== null ? entry.querySelector('.action-view-note') : null;
}
+ viewerButtonShow(index, noteId) {
+ const viewerButton = this.viewerButtonFind(index);
+ if (viewerButton === null) {
+ return;
+ }
+ viewerButton.classList.remove('pending', 'disabled');
+ viewerButton.dataset.noteId = noteId;
+ }
+
static delay(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}