Skip to content

Commit

Permalink
fix profile select on search page not updating (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 authored Apr 25, 2024
1 parent 0c29b10 commit af2dc44
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions ext/js/display/search-display-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class SearchDisplayController {
this._clipboardMonitorEnableCheckbox = querySelectorNotNull(document, '#clipboard-monitor-enable');
/** @type {HTMLInputElement} */
this._wanakanaEnableCheckbox = querySelectorNotNull(document, '#wanakana-enable');
/** @type {HTMLSelectElement} */
this._profileSelect = querySelectorNotNull(document, '#profile-select');
/** @type {HTMLElement} */
this._wanakanaSearchOption = querySelectorNotNull(document, '#search-option-wanakana');
/** @type {EventListenerCollection} */
Expand Down Expand Up @@ -109,12 +111,8 @@ export class SearchDisplayController {

const displayOptions = this._display.getOptions();
if (displayOptions !== null) {
this._onDisplayOptionsUpdated({options: displayOptions});
await this._onDisplayOptionsUpdated({options: displayOptions});
}

const {profiles, profileCurrent} = await this._display.application.api.optionsGetFull();

this._updateProfileSelect(profiles, profileCurrent);
}

/**
Expand Down Expand Up @@ -182,10 +180,17 @@ export class SearchDisplayController {
/**
* @param {import('display').EventArgument<'optionsUpdated'>} details
*/
_onDisplayOptionsUpdated({options}) {
async _onDisplayOptionsUpdated({options}) {
this._clipboardMonitorEnabled = options.clipboard.enableSearchPageMonitor;
this._updateClipboardMonitorEnabled();
this._updateWanakanaCheckbox(options);
await this._updateProfileSelect();
}

/**
* @param {import('settings').ProfileOptions} options
*/
_updateWanakanaCheckbox(options) {
const {language, enableWanakana} = options.general;
const wanakanaEnabled = language === 'ja' && enableWanakana;
this._wanakanaEnableCheckbox.checked = wanakanaEnabled;
Expand Down Expand Up @@ -590,15 +595,16 @@ export class SearchDisplayController {
return element instanceof HTMLElement && !!element.isContentEditable;
}

/**
* @param {import('settings').Profile[]} profiles
* @param {number} profileCurrent
*/
_updateProfileSelect(profiles, profileCurrent) {
/** @type {HTMLSelectElement} */
const select = querySelectorNotNull(document, '#profile-select');
/** */
async _updateProfileSelect() {
const {profiles, profileCurrent} = await this._display.application.api.optionsGetFull();

/** @type {HTMLElement} */
const optionGroup = querySelectorNotNull(document, '#profile-select-option-group');
while (optionGroup.firstChild) {
optionGroup.removeChild(optionGroup.firstChild);
}

const fragment = document.createDocumentFragment();
for (let i = 0, ii = profiles.length; i < ii; ++i) {
const {name} = profiles[i];
Expand All @@ -609,8 +615,8 @@ export class SearchDisplayController {
}
optionGroup.textContent = '';
optionGroup.appendChild(fragment);
select.value = `${profileCurrent}`;
this._profileSelect.value = `${profileCurrent}`;

select.addEventListener('change', this._onProfileSelectChange.bind(this), false);
this._profileSelect.addEventListener('change', this._onProfileSelectChange.bind(this), false);
}
}

0 comments on commit af2dc44

Please sign in to comment.