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

Introduce pending in query ModeSelector #5470

Merged
merged 1 commit into from
Jan 29, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 54 additions & 3 deletions src/query/ModeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ export class QueryModeSelector {
*/
this.action_ = ngeoQueryAction.REPLACE;

/**
* A flag that determines whether a request is currently pending
* in the query component.
*
* While this flag is set, the mode can't change due to keyboard
* keys being pressed.
*
* @type {boolean}
* @private
*/
this.pending_ = false;

/**
* A flag than handles the change of mode while a request was
* still pending.
* @type {boolean}
* @private
*/
this.wasPending_ = false;

/**
* If a key is pressed, it can temporarily change the currently
* active action. When that happens, the currently active action
Expand Down Expand Up @@ -133,6 +153,28 @@ export class QueryModeSelector {
this.mode_ = mode;
}

/**
* @return {boolean} Whether a request is currently pending or not.
*/
get pending() {
return this.pending_;
}

/**
* @param {boolean} pending Whether a request is currently pending or not.
*/
set pending(pending) {
this.pending_ = pending;

// If we're no longer pending, but we were pending while a change
// of mode tried to occur, then do it here.
if (!pending && this.wasPending_ && this.previousMode_) {
this.wasPending_ = false;
this.mode = this.previousMode_;
this.previousMode_ = null;
}
}

// Handlers

/**
Expand All @@ -144,6 +186,11 @@ export class QueryModeSelector {
return;
}

// No need to do anything on "keydown" if a request is already pending
if (this.pending) {
return;
}

const key = evt.key;
if (this.keysAction_.includes(key) && !this.previousAction_) {
// An 'action' key was pressed and none were already previously
Expand Down Expand Up @@ -188,9 +235,13 @@ export class QueryModeSelector {
// On any 'keyup', if no 'ctrl' (or 'meta' on mac) is pressed and
// there is a previous mode set, then set it as new active mode.
if (!(evt.metaKey || evt.ctrlKey) && this.previousMode_) {
this.mode = this.previousMode_;
this.previousMode_ = null;
updateScope = true;
if (this.pending) {
this.wasPending_ = true;
} else {
this.mode = this.previousMode_;
this.previousMode_ = null;
updateScope = true;
}
}

// If the active action key was released, then restore the
Expand Down
16 changes: 15 additions & 1 deletion src/query/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ class QueryController {
const limit = this.getLimitOption_();
const map = this.map;

this.ngeoQueryModeSelector_.pending = true;

this.ngeoMapQuerent_.issue({
action,
extent,
Expand All @@ -363,6 +365,7 @@ class QueryController {
.then(() => {
// "finally"
this.vectorSource_.clear();
this.ngeoQueryModeSelector_.pending = false;
});
}

Expand All @@ -381,6 +384,8 @@ class QueryController {
const limit = this.getLimitOption_();
const map = this.map;

this.ngeoQueryModeSelector_.pending = true;

this.ngeoMapQuerent_.issue({
action,
geometry,
Expand All @@ -392,6 +397,7 @@ class QueryController {
.then(() => {
// "finally"
this.vectorSource_.clear();
this.ngeoQueryModeSelector_.pending = false;
});
}

Expand All @@ -412,11 +418,19 @@ class QueryController {
const coordinate = evt.coordinate;
const map = this.map;

this.ngeoQueryModeSelector_.pending = true;

this.ngeoMapQuerent_.issue({
action,
coordinate,
map
});
})
.then(() => {})
.catch(() => {})
.then(() => {
// "finally"
this.ngeoQueryModeSelector_.pending = false;
});
}

/**
Expand Down