Skip to content

Commit

Permalink
Add helper text when search with no dictionaries enabled (#1220)
Browse files Browse the repository at this point in the history
* Helper text when no dictionary enabled

* Don't need to search if there is no dictionary entries

* update helper link
  • Loading branch information
khaitruong922 authored Jul 14, 2024
1 parent ee6185a commit 18149b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
19 changes: 17 additions & 2 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ export class Display extends EventDispatcher {
async _setContentTermsOrKanji(type, urlSearchParams, token) {
const lookup = (urlSearchParams.get('lookup') !== 'false');
const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off');
const hasEnabledDictionaries = this._options ? this._options.dictionaries.some(({enabled}) => enabled) : false;

// Set query
let query = urlSearchParams.get('query');
Expand Down Expand Up @@ -1331,7 +1332,7 @@ export class Display extends EventDispatcher {

let {dictionaryEntries} = content;
if (!Array.isArray(dictionaryEntries)) {
dictionaryEntries = lookup && query.length > 0 ? await this._findDictionaryEntries(type === 'kanji', query, wildcardsEnabled, optionsContext) : [];
dictionaryEntries = hasEnabledDictionaries && lookup && query.length > 0 ? await this._findDictionaryEntries(type === 'kanji', query, wildcardsEnabled, optionsContext) : [];
if (this._setContentToken !== token) { return; }
content.dictionaryEntries = dictionaryEntries;
changeHistory = true;
Expand Down Expand Up @@ -1367,7 +1368,8 @@ export class Display extends EventDispatcher {
this._dictionaryEntries = dictionaryEntries;

this._updateNavigationAuto();
this._setNoContentVisible(dictionaryEntries.length === 0 && lookup);
this._setNoContentVisible(hasEnabledDictionaries && dictionaryEntries.length === 0 && lookup);
this._setNoDictionariesVisible(!hasEnabledDictionaries);

const container = this._container;
container.textContent = '';
Expand Down Expand Up @@ -1424,6 +1426,7 @@ export class Display extends EventDispatcher {

this._updateNavigation(false, false);
this._setNoContentVisible(false);
this._setNoDictionariesVisible(false);
this._setQuery('', '', 0);

this._triggerContentUpdateStart();
Expand Down Expand Up @@ -1452,6 +1455,18 @@ export class Display extends EventDispatcher {
}
}

/**
* @param {boolean} visible
*/
_setNoDictionariesVisible(visible) {
/** @type {?HTMLElement} */
const noDictionaries = document.querySelector('#no-dictionaries');

if (noDictionaries !== null) {
noDictionaries.hidden = !visible;
}
}

/**
* @param {string} query
* @param {string} fullQuery
Expand Down
6 changes: 6 additions & 0 deletions ext/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
</div>
</div>

<div id="no-dictionaries" hidden>
<div class="entry">
<p>No dictionaries have been installed or enabled yet.</p>
<p><a href="/settings.html#!dictionaries" target="_blank">Go to Dictionaries settings.</a></p>
</div>
</div>
<div id="error-extension-unloaded" hidden>
<div class="entry">
<h1>Yomitan Updated!</h1>
Expand Down
6 changes: 6 additions & 0 deletions ext/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ <h1>Yomitan Search</h1>
</div>
</div>

<div id="no-dictionaries" hidden>
<div class="entry">
<p>No dictionaries have been installed or enabled yet.</p>
<p><a href="/settings.html#!dictionaries" target="_blank">Go to Dictionaries settings.</a></p>
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 18149b6

Please sign in to comment.