Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable download button when dictionary is already installed #1336

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ext/js/pages/settings/dictionary-import-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,20 @@ export class DictionaryImportController {
return;
}

const installedDictionaries = await this._settingsController.getDictionaryInfo();
/** @type {Set<string>} */
const installedDictionaryNames = new Set();
/** @type {Set<string>} */
const installedDictionaryDownloadUrls = new Set();
for (const dictionary of installedDictionaries) {
installedDictionaryNames.add(dictionary.title);
if (dictionary.downloadUrl) {
installedDictionaryDownloadUrls.add(dictionary.downloadUrl);
}
}

for (const {property, element} of recommendedDictionaryCategories) {
this._renderRecommendedDictionaryGroup(recommendedDictionaries[language][property], element);
this._renderRecommendedDictionaryGroup(recommendedDictionaries[language][property], element, installedDictionaryNames, installedDictionaryDownloadUrls);
}

/** @type {NodeListOf<HTMLElement>} */
Expand All @@ -191,8 +203,10 @@ export class DictionaryImportController {
*
* @param {import('dictionary-recommended.js').Dictionary[]} recommendedDictionaries
* @param {HTMLElement} dictionariesList
* @param {Set<string>} installedDictionaryNames
* @param {Set<string>} installedDictionaryDownloadUrls
*/
_renderRecommendedDictionaryGroup(recommendedDictionaries, dictionariesList) {
_renderRecommendedDictionaryGroup(recommendedDictionaries, dictionariesList, installedDictionaryNames, installedDictionaryDownloadUrls) {
const dictionariesListParent = dictionariesList.parentElement;
dictionariesList.innerHTML = '';
for (const dictionary of recommendedDictionaries) {
Expand All @@ -202,7 +216,9 @@ export class DictionaryImportController {
}
const template = this._settingsController.instantiateTemplate('recommended-dictionaries-list-item');
const label = querySelectorNotNull(template, '.settings-item-label');
/** @type {HTMLButtonElement} */
const button = querySelectorNotNull(template, '.action-button[data-action=import-recommended-dictionary]');
button.disabled = installedDictionaryNames.has(dictionary.name) || installedDictionaryDownloadUrls.has(dictionary.url);

const urlAttribute = document.createAttribute('data-import-url');
urlAttribute.value = dictionary.url;
Expand Down
Loading