aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/mecab-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/pages/settings/mecab-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/pages/settings/mecab-controller.js')
-rw-r--r--ext/js/pages/settings/mecab-controller.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/ext/js/pages/settings/mecab-controller.js b/ext/js/pages/settings/mecab-controller.js
index a839fc21..4e2b02c6 100644
--- a/ext/js/pages/settings/mecab-controller.js
+++ b/ext/js/pages/settings/mecab-controller.js
@@ -19,48 +19,61 @@
import {yomitan} from '../../yomitan.js';
export class MecabController {
- constructor(settingsController) {
- this._settingsController = settingsController;
+ constructor() {
+ /** @type {?HTMLButtonElement} */
this._testButton = null;
+ /** @type {?HTMLElement} */
this._resultsContainer = null;
+ /** @type {boolean} */
this._testActive = false;
}
+ /** */
prepare() {
- this._testButton = document.querySelector('#test-mecab-button');
- this._resultsContainer = document.querySelector('#test-mecab-results');
+ this._testButton = /** @type {HTMLButtonElement} */ (document.querySelector('#test-mecab-button'));
+ this._resultsContainer = /** @type {HTMLElement} */ (document.querySelector('#test-mecab-results'));
this._testButton.addEventListener('click', this._onTestButtonClick.bind(this), false);
}
// Private
+ /**
+ * @param {MouseEvent} e
+ */
_onTestButtonClick(e) {
e.preventDefault();
this._testMecab();
}
+ /** */
async _testMecab() {
if (this._testActive) { return; }
try {
this._testActive = true;
- this._testButton.disabled = true;
- this._resultsContainer.textContent = '';
- this._resultsContainer.hidden = true;
+ const resultsContainer = /** @type {HTMLElement} */ (this._resultsContainer);
+ /** @type {HTMLButtonElement} */ (this._testButton).disabled = true;
+ resultsContainer.textContent = '';
+ resultsContainer.hidden = true;
await yomitan.api.testMecab();
this._setStatus('Connection was successful', false);
} catch (e) {
- this._setStatus(e.message, true);
+ this._setStatus(e instanceof Error ? e.message : `${e}`, true);
} finally {
this._testActive = false;
- this._testButton.disabled = false;
+ /** @type {HTMLButtonElement} */ (this._testButton).disabled = false;
}
}
+ /**
+ * @param {string} message
+ * @param {boolean} isError
+ */
_setStatus(message, isError) {
- this._resultsContainer.textContent = message;
- this._resultsContainer.hidden = false;
- this._resultsContainer.classList.toggle('danger-text', isError);
+ const resultsContainer = /** @type {HTMLElement} */ (this._resultsContainer);
+ resultsContainer.textContent = message;
+ resultsContainer.hidden = false;
+ resultsContainer.classList.toggle('danger-text', isError);
}
}