Use an overridable property to control progress indicator visibility (#1041)
This commit is contained in:
parent
ea7b8621c3
commit
a48ac37815
@ -21,10 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class QueryParser extends EventDispatcher {
|
class QueryParser extends EventDispatcher {
|
||||||
constructor({getOptionsContext, setSpinnerVisible, documentUtil}) {
|
constructor({getOptionsContext, progressIndicatorVisible, documentUtil}) {
|
||||||
super();
|
super();
|
||||||
this._getOptionsContext = getOptionsContext;
|
this._getOptionsContext = getOptionsContext;
|
||||||
this._setSpinnerVisible = setSpinnerVisible;
|
this._progressIndicatorVisible = progressIndicatorVisible;
|
||||||
this._selectedParser = null;
|
this._selectedParser = null;
|
||||||
this._documentUtil = documentUtil;
|
this._documentUtil = documentUtil;
|
||||||
this._parseResults = [];
|
this._parseResults = [];
|
||||||
@ -63,17 +63,18 @@ class QueryParser extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setText(text) {
|
async setText(text) {
|
||||||
this._setSpinnerVisible(true);
|
const overrideToken = this._progressIndicatorVisible.setOverride(true);
|
||||||
|
try {
|
||||||
|
this._setPreview(text);
|
||||||
|
|
||||||
this._setPreview(text);
|
this._parseResults = await api.textParse(text, this._getOptionsContext());
|
||||||
|
this._refreshSelectedParser();
|
||||||
|
|
||||||
this._parseResults = await api.textParse(text, this._getOptionsContext());
|
this._renderParserSelect();
|
||||||
this._refreshSelectedParser();
|
this._renderParseResult();
|
||||||
|
} finally {
|
||||||
this._renderParserSelect();
|
this._progressIndicatorVisible.clearOverride(overrideToken);
|
||||||
this._renderParseResult();
|
}
|
||||||
|
|
||||||
this._setSpinnerVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
@ -69,12 +69,13 @@ class Display extends EventDispatcher {
|
|||||||
this._defaultTitleMaxLength = 1000;
|
this._defaultTitleMaxLength = 1000;
|
||||||
this._fullQuery = '';
|
this._fullQuery = '';
|
||||||
this._documentUtil = new DocumentUtil();
|
this._documentUtil = new DocumentUtil();
|
||||||
|
this._progressIndicatorVisible = new DynamicProperty(false);
|
||||||
this._queryParserVisible = false;
|
this._queryParserVisible = false;
|
||||||
this._queryParserVisibleOverride = null;
|
this._queryParserVisibleOverride = null;
|
||||||
this._queryParserContainer = document.querySelector('#query-parser-container');
|
this._queryParserContainer = document.querySelector('#query-parser-container');
|
||||||
this._queryParser = new QueryParser({
|
this._queryParser = new QueryParser({
|
||||||
getOptionsContext: this.getOptionsContext.bind(this),
|
getOptionsContext: this.getOptionsContext.bind(this),
|
||||||
setSpinnerVisible: this.setSpinnerVisible.bind(this),
|
progressIndicatorVisible: this._progressIndicatorVisible,
|
||||||
documentUtil: this._documentUtil
|
documentUtil: this._documentUtil
|
||||||
});
|
});
|
||||||
this._mode = null;
|
this._mode = null;
|
||||||
@ -182,6 +183,7 @@ class Display extends EventDispatcher {
|
|||||||
['popupMessage', {async: 'dynamic', handler: this._onDirectMessage.bind(this)}]
|
['popupMessage', {async: 'dynamic', handler: this._onDirectMessage.bind(this)}]
|
||||||
]);
|
]);
|
||||||
window.addEventListener('focus', this._onWindowFocus.bind(this), false);
|
window.addEventListener('focus', this._onWindowFocus.bind(this), false);
|
||||||
|
this._progressIndicatorVisible.on('change', this._onProgressIndicatorVisibleChanged.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeState() {
|
initializeState() {
|
||||||
@ -337,12 +339,6 @@ class Display extends EventDispatcher {
|
|||||||
return document.title;
|
return document.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSpinnerVisible(visible) {
|
|
||||||
if (this._spinner !== null) {
|
|
||||||
this._spinner.hidden = !visible;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerActions(actions) {
|
registerActions(actions) {
|
||||||
for (const [name, handler] of actions) {
|
for (const [name, handler] of actions) {
|
||||||
this._actions.set(name, handler);
|
this._actions.set(name, handler);
|
||||||
@ -566,6 +562,11 @@ class Display extends EventDispatcher {
|
|||||||
this._nextTermView();
|
this._nextTermView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onProgressIndicatorVisibleChanged({value}) {
|
||||||
|
if (this._spinner === null) { return; }
|
||||||
|
this._spinner.hidden = !value;
|
||||||
|
}
|
||||||
|
|
||||||
_onWindowFocus() {
|
_onWindowFocus() {
|
||||||
const target = this._contentScrollFocusElement;
|
const target = this._contentScrollFocusElement;
|
||||||
if (target === null) { return; }
|
if (target === null) { return; }
|
||||||
@ -1133,9 +1134,8 @@ class Display extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _noteAdd(definition, mode) {
|
async _noteAdd(definition, mode) {
|
||||||
|
const overrideToken = this._progressIndicatorVisible.setOverride(true);
|
||||||
try {
|
try {
|
||||||
this.setSpinnerVisible(true);
|
|
||||||
|
|
||||||
const noteContext = await this._getNoteContext();
|
const noteContext = await this._getNoteContext();
|
||||||
const noteId = await this._addDefinition(definition, mode, noteContext);
|
const noteId = await this._addDefinition(definition, mode, noteContext);
|
||||||
if (noteId) {
|
if (noteId) {
|
||||||
@ -1151,14 +1151,13 @@ class Display extends EventDispatcher {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.onError(e);
|
this.onError(e);
|
||||||
} finally {
|
} finally {
|
||||||
this.setSpinnerVisible(false);
|
this._progressIndicatorVisible.clearOverride(overrideToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _audioPlay(definition, expressionIndex, entryIndex) {
|
async _audioPlay(definition, expressionIndex, entryIndex) {
|
||||||
|
const overrideToken = this._progressIndicatorVisible.setOverride(true);
|
||||||
try {
|
try {
|
||||||
this.setSpinnerVisible(true);
|
|
||||||
|
|
||||||
const {expression, reading} = expressionIndex === -1 ? definition : definition.expressions[expressionIndex];
|
const {expression, reading} = expressionIndex === -1 ? definition : definition.expressions[expressionIndex];
|
||||||
|
|
||||||
this._stopPlayingAudio();
|
this._stopPlayingAudio();
|
||||||
@ -1204,7 +1203,7 @@ class Display extends EventDispatcher {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.onError(e);
|
this.onError(e);
|
||||||
} finally {
|
} finally {
|
||||||
this.setSpinnerVisible(false);
|
this._progressIndicatorVisible.clearOverride(overrideToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user