Skip to content

Commit

Permalink
Dictionary delete queue
Browse files Browse the repository at this point in the history
dictionary delete queue

<rikaitan.link>NTQ3YTYyODRiYjhhMGY1Y2QyNmE4NGIzNWViNGU3ZWJjYTgyNDc5Mgo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Sep 14, 2024
1 parent b941a8e commit 0b039bd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class DictionaryEntry {
const bodyNode = e.detail.menu.bodyNode;
const count = this._dictionaryController.dictionaryOptionCount;
this._setMenuActionEnabled(bodyNode, 'moveTo', count > 1);
this._setMenuActionEnabled(bodyNode, 'delete', !this._dictionaryController.isDictionaryInDeleteQueue(this.dictionaryTitle));
}

/**
Expand Down Expand Up @@ -505,6 +506,8 @@ export class DictionaryController {
this._extraInfo = null;
/** @type {boolean} */
this._isDeleting = false;
/** @type {string[]} */
this._dictionaryDeleteQueue = [];
}

/** @type {import('./modal-controller.js').ModalController} */
Expand Down Expand Up @@ -563,7 +566,6 @@ export class DictionaryController {
* @param {string} dictionaryTitle
*/
deleteDictionary(dictionaryTitle) {
if (this._isDeleting) { return; }
const modal = /** @type {import('./modal.js').Modal} */ (this._deleteDictionaryModal);
modal.node.dataset.dictionaryTitle = dictionaryTitle;
/** @type {Element} */
Expand Down Expand Up @@ -849,7 +851,7 @@ export class DictionaryController {
if (typeof title !== 'string') { return; }
delete modal.node.dataset.dictionaryTitle;

void this._deleteDictionary(title);
void this._enqueueDictionaryDelete(title);
}

/**
Expand Down Expand Up @@ -1051,6 +1053,30 @@ export class DictionaryController {
this._updateDictionaryEntryCount();
}


/**
* @param {string} dictionaryTitle
* @returns {boolean}
*/
isDictionaryInDeleteQueue(dictionaryTitle) {
return this._dictionaryDeleteQueue.includes(dictionaryTitle);
}

/**
* @param {string} dictionaryTitle
*/
async _enqueueDictionaryDelete(dictionaryTitle) {
if (this.isDictionaryInDeleteQueue(dictionaryTitle)) { return; }
this._dictionaryDeleteQueue.push(dictionaryTitle);
if (this._isDeleting) { return; }
while (this._dictionaryDeleteQueue.length > 0) {
const title = this._dictionaryDeleteQueue[0];
if (!title) { continue; }
await this._deleteDictionary(title);
void this._dictionaryDeleteQueue.shift();
}
}

/**
* @param {string} dictionaryTitle
*/
Expand Down

0 comments on commit 0b039bd

Please sign in to comment.