Skip to content

Commit

Permalink
Display the stacked add buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
eloyrobillard committed Mar 1, 2024
1 parent 465d51a commit 1b860a6
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ button.action-button:active {
.icon[data-icon=view-note] { background-image: url('/images/view-note.svg'); }
.icon[data-icon=add-term-kanji] { background-image: url('/images/add-term-kanji.svg'); }
.icon[data-icon=add-term-kana] { background-image: url('/images/add-term-kana.svg'); }
.icon[data-icon=add-duplicate-term-kanji] { background-image: url('/images/add-duplicate-term-kanji.svg'); }
.icon[data-icon=add-duplicate-term-kana] { background-image: url('/images/add-duplicate-term-kana.svg'); }
.icon[data-icon=play-audio] { background-image: url('/images/play-audio.svg'); }
.icon[data-icon=source-term] { background-image: url('/images/source-term.svg'); }
.icon[data-icon=entry-current] { background-image: url('/images/entry-current.svg'); }
Expand Down
40 changes: 40 additions & 0 deletions ext/images/add-duplicate-term-kana.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions ext/images/add-duplicate-term-kanji.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions ext/js/display/display-anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,31 @@ export class DisplayAnki {
}
}

/**
* @param {HTMLButtonElement} button
*/
_showDuplicateAddButton(button) {
const isKanjiAdd = button.dataset.mode === 'term-kanji';

const title = button.getAttribute('title');

if (title) {
button.setAttribute('title', title.replace(/Add (?!duplicate)/, 'Add duplicate '));
}

const {hotkey} = button.dataset;

if (hotkey) {
button.dataset.hotkey = hotkey.replace(/Add (?!duplicate)/, 'Add duplicate ');
}

const actionIcon = button.querySelector('.action-icon');

if (actionIcon instanceof HTMLElement) {
actionIcon.dataset.icon = isKanjiAdd ? 'add-duplicate-term-kanji' : 'add-duplicate-term-kana';
}
}

/**
* @param {import('display-anki').DictionaryEntryDetails[]} dictionaryEntryDetails
*/
Expand All @@ -383,6 +408,11 @@ export class DisplayAnki {
if (button !== null) {
button.disabled = !canAdd;
button.hidden = (ankiError !== null);

// If entry has noteIds, show the "add duplicate" button.
if (Array.isArray(noteIds) && noteIds.length > 0) {
this._showDuplicateAddButton(button);
}
}

if (Array.isArray(noteIds) && noteIds.length > 0) {
Expand Down Expand Up @@ -507,6 +537,9 @@ export class DisplayAnki {
allErrors.push(toError(e));
}
}
// Now that this dictionary entry has a duplicate in Anki, show the "add duplicate" buttons.
this._showDuplicateAddButton(button);

this._updateViewNoteButton(dictionaryEntryIndex, [noteId], true);
}
}
Expand Down

0 comments on commit 1b860a6

Please sign in to comment.