Skip to content

Commit

Permalink
Fixed behavior of suggest and route info (#42)
Browse files Browse the repository at this point in the history
<!--

Thank you for submitting a pull request!

Here's a checklist you might find useful.
[ ] There is an associated issue that is labelled
  'Bug' or 'help wanted' or is in the Community milestone
[ ] Code is up-to-date with the `main` branch
[ ] You've successfully run `npm test` locally
[ ] There are new or updated tests validating the change

-->

Fixes #
  • Loading branch information
matthew44-mappable authored Nov 22, 2024
1 parent 547dca8 commit 6f89fbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/controls/MMapRouteControl/MMapWaypointInput/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ export class MMapWaypointInput extends mappable.MMapComplexEntity<MMapWaypointIn

private _onFocusInput = (_event: FocusEvent) => {
this._isInputFocused = true;
this._suggestComponent.update({suggestNavigationAction: undefined});
this._suggestComponent.update({
searchInputValue: this.getValue(),
suggestNavigationAction: undefined
});
this._addDirectChild(this._suggestComponent);
this._updateIndicatorStatus('focus');
};
Expand Down
9 changes: 6 additions & 3 deletions src/controls/MMapRouteControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity<MMapRouteControl
if (result === null) {
this._waypoints[waypointIndex] = null;
this._onUpdateWaypoints(null, waypointIndex);
this._clearInfo();
return;
}

Expand All @@ -275,11 +276,15 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity<MMapRouteControl
private _clearAll = () => {
this._waypointInputFromElement.update({waypoint: null});
this._waypointInputToElement.update({waypoint: null});
this._clearInfo();
};

private _clearInfo = () => {
this._routeInfoElement.replaceChildren();
if (this._routeInfoElement.parentElement === this._rootElement) {
this._rootElement.removeChild(this._routeInfoElement);
}
};
}

private _changeOrder = () => {
const [fromOld, toOld] = this._waypoints;
Expand Down Expand Up @@ -336,7 +341,6 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity<MMapRouteControl

this._routeInfoElement.classList.remove('mappable--route-control_info__error');
this._routeInfoElement.replaceChildren(createLoadingSpinner());

try {
const response = (await this._props.route?.({params, map: this.root})) ?? (await mappable.route(params));
const route = response[0].toRoute();
Expand Down Expand Up @@ -377,7 +381,6 @@ class MMapCommonRouteControl extends mappable.MMapComplexEntity<MMapRouteControl
});
const formattedLength = formatDistance(totalLength);
const formattedDuration = formatDuration(totalDuration);

return [
createInfoElementComponent('time', formattedDuration),
createInfoElementComponent('distance', formattedLength)
Expand Down
4 changes: 2 additions & 2 deletions src/controls/MMapSearchControl/MMapSuggest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class MMapSuggest extends mappable.MMapComplexEntity<MMapSuggestProps> {
}

private _updateSuggestList = async (searchInputValue: MMapSuggestProps['searchInputValue']) => {
this._removeSuggestItems();

const suggestResult =
(await this._props.suggest?.({text: searchInputValue, map: this.root})) ??
(await mappable.suggest({text: searchInputValue}));

this._removeSuggestItems();

this._addSuggestItems(suggestResult, this._props.onSuggestClick);

this._getSuggestElements().at(0)?.classList.add(ACTIVE_CLASS);
Expand Down

0 comments on commit 6f89fbb

Please sign in to comment.