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

fix profile select on search page not updating #858

Merged
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
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);
}
}