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

Add helper text when search with no dictionaries enabled #1220

Merged
merged 6 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
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
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