Skip to content

Commit

Permalink
When no dictionary is enabled, update preview after enable dictionary (
Browse files Browse the repository at this point in the history
…#1232)

* Fix preview not update when enable dictionary

* Add dictionaryEnabled event

* Update logic

* align

* Fix lint
  • Loading branch information
khaitruong922 authored Jul 16, 2024
1 parent 27e6e65 commit 22da9df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ export class DictionaryController {
}

const hasEnabledDictionary = (enabledDictionaryCountValid > 0);
if (hasEnabledDictionary) {
this._settingsController.trigger('dictionaryEnabled', {});
}
for (const node of /** @type {NodeListOf<HTMLElement>} */ (this._noDictionariesEnabledWarnings)) {
node.hidden = hasEnabledDictionary;
}
Expand Down
6 changes: 6 additions & 0 deletions ext/js/pages/settings/popup-preview-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class PopupPreviewController {
this._frame.addEventListener('load', this._onFrameLoad.bind(this), false);
this._settingsController.on('optionsContextChanged', this._onOptionsContextChange.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
this._settingsController.on('dictionaryEnabled', this._onOptionsContextChange.bind(this));
const languageSelect = querySelectorNotNull(document, '#language-select');
languageSelect.addEventListener(
/** @type {string} */ ('settingChanged'),
Expand Down Expand Up @@ -86,6 +87,11 @@ export class PopupPreviewController {
this._invoke('updateOptionsContext', {optionsContext});
}

/** */
_onDictionaryEnabled() {
this._invoke('updateSearch', {});
}

/**
* @param {import('settings-controller').EventArgument<'optionsChanged'>} details
*/
Expand Down
1 change: 1 addition & 0 deletions ext/js/pages/settings/popup-preview-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class PopupPreviewFrame {
['setCustomOuterCss', this._setCustomOuterCss.bind(this)],
['updateOptionsContext', this._updateOptionsContext.bind(this)],
['setLanguageExampleText', this._setLanguageExampleText.bind(this)],
['updateSearch', this._updateSearch.bind(this)],
]);
/* eslint-enable @stylistic/no-multi-spaces */
}
Expand Down
4 changes: 4 additions & 0 deletions types/ext/popup-preview-frame.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export type ApiSurface = {
};
return: void;
};
updateSearch: {
params: Record<string, never>;
return: void;
};
};

export type ApiParams<TName extends ApiNames> = BaseApiParams<ApiSurface[TName]>;
Expand Down
1 change: 1 addition & 0 deletions types/ext/settings-controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type Events = {
dictionarySettingsReordered: {
source: DictionaryController;
};
dictionaryEnabled: Record<string, never>;
scanInputsChanged: {
source: ScanInputsController | ScanInputsSimpleController;
};
Expand Down

0 comments on commit 22da9df

Please sign in to comment.