Fix place route being active after closing place details
Depending on where a place was opened from, it now goes back to the index or (active) search route
This commit is contained in:
@@ -33,7 +33,9 @@ export default class SearchController extends Controller {
|
|||||||
|
|
||||||
// 2. If it's a back navigation to the exact same search, resolve instantly with no animation
|
// 2. If it's a back navigation to the exact same search, resolve instantly with no animation
|
||||||
if (isSameSearch && hasResults) {
|
if (isSameSearch && hasResults) {
|
||||||
|
if (this.mapUi.isSidebarVisible) {
|
||||||
this.mapUi.showSidebar();
|
this.mapUi.showSidebar();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ export default class ApplicationComponent extends Component {
|
|||||||
this.mapUi.hideSidebar();
|
this.mapUi.hideSidebar();
|
||||||
if (name === 'menu' || name.startsWith('lists')) {
|
if (name === 'menu' || name.startsWith('lists')) {
|
||||||
this.router.transitionTo('index');
|
this.router.transitionTo('index');
|
||||||
|
} else if (name === 'place') {
|
||||||
|
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||||
|
this.router.transitionTo('search', {
|
||||||
|
queryParams: this.mapUi.currentSearch,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.router.transitionTo('index');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,13 @@ export default class PlaceTemplate extends Component {
|
|||||||
close() {
|
close() {
|
||||||
this.mapUi.clearSelection();
|
this.mapUi.clearSelection();
|
||||||
this.mapUi.hideSidebar();
|
this.mapUi.hideSidebar();
|
||||||
|
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||||
|
this.router.transitionTo('search', {
|
||||||
|
queryParams: this.mapUi.currentSearch,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.router.transitionTo('index');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ module('Acceptance | navigation', function (hooks) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('closing the sidebar resets the returnToSearch flag', async function (assert) {
|
test('closing the sidebar transitions back to search route when opened from search results', async function (assert) {
|
||||||
const mapUi = this.owner.lookup('service:map-ui');
|
const mapUi = this.owner.lookup('service:map-ui');
|
||||||
|
|
||||||
await visit('/search?lat=1&lon=1');
|
await visit('/search?lat=1&lon=1');
|
||||||
@@ -97,7 +97,22 @@ module('Acceptance | navigation', function (hooks) {
|
|||||||
await click('.close-btn');
|
await click('.close-btn');
|
||||||
|
|
||||||
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
||||||
assert.ok(currentURL().includes('/place/'), 'Remains on place route');
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
'/search?lat=1&lon=1',
|
||||||
|
'Should transition back to search route'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('closing the sidebar when visiting a place directly transitions to index', async function (assert) {
|
||||||
|
await visit('/place/osm:node:123');
|
||||||
|
assert.ok(currentURL().includes('/place/'), 'Visited place directly');
|
||||||
|
|
||||||
|
// Click the Close (X) button
|
||||||
|
await click('.close-btn');
|
||||||
|
|
||||||
|
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
||||||
|
assert.strictEqual(currentURL(), '/', 'Should transition back to index');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('navigating directly to place and back closes sidebar', async function (assert) {
|
test('navigating directly to place and back closes sidebar', async function (assert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user