Keep search results, only hide sidebar when closed

This commit is contained in:
2026-04-27 14:27:25 +01:00
parent a0b4a4b3f3
commit d2eb888dcf
9 changed files with 69 additions and 46 deletions

View File

@@ -1144,6 +1144,8 @@ export default class MapComponent extends Component {
this.mapUi.returnToSearch = true;
}
this.mapUi.preventNextZoom = true;
this.mapUi.selectPlace(place, { preventZoom: true });
this.mapUi.showSidebar();
this.router.transitionTo('place', place);
};

View File

@@ -96,6 +96,7 @@ export default class PlaceRoute extends Route {
if (model) {
const options = { preventZoom: this.mapUi.preventNextZoom };
this.mapUi.selectPlace(model, options);
this.mapUi.showSidebar();
this.mapUi.preventNextZoom = false;
}
// Stop the pulse animation if it was running (e.g. redirected from search)

View File

@@ -22,6 +22,7 @@ export default class PlaceNewRoute extends Route {
this.mapUi.updateCreationCoordinates(model.lat, model.lon);
}
this.mapUi.startCreating();
this.mapUi.showSidebar();
}
deactivate() {

View File

@@ -193,6 +193,7 @@ export default class SearchRoute extends Route {
// Ensure pulse is stopped if we reach here
this.mapUi.stopSearch();
this.mapUi.setSearchResults(model);
this.mapUi.showSidebar();
// Store current search params to allow "Up" navigation from place details
const { q, category, lat, lon } = this.paramsFor('search');

View File

@@ -17,6 +17,15 @@ export default class MapUiService extends Service {
@tracked searchResults = [];
@tracked currentSearch = null;
@tracked loadingState = null;
@tracked isSidebarVisible = false;
showSidebar() {
this.isSidebarVisible = true;
}
hideSidebar() {
this.isSidebarVisible = false;
}
selectPlace(place, options = {}) {
this.selectedPlace = place;

View File

@@ -18,12 +18,13 @@ export default class ApplicationComponent extends Component {
@tracked isAppMenuOpen = false;
get isSidebarOpen() {
// We consider the sidebar "open" if we are in search or place routes.
// We consider the sidebar "open" if we are in search or place routes AND it's visible.
// This helps the map know if it should shift the center or adjust view.
return (
this.router.currentRouteName === 'place' ||
this.router.currentRouteName === 'place.new' ||
this.router.currentRouteName === 'search'
this.mapUi.isSidebarVisible &&
(this.router.currentRouteName === 'place' ||
this.router.currentRouteName === 'place.new' ||
this.router.currentRouteName === 'search')
);
}
@@ -48,13 +49,12 @@ export default class ApplicationComponent extends Component {
handleOutsideClick() {
if (this.isAppMenuOpen) {
this.closeAppMenu();
} else if (this.router.currentRouteName === 'search') {
this.router.transitionTo('index');
} else if (this.router.currentRouteName === 'place') {
// If in place route, decide if we want to go back to search or index
// For now, let's go to index or maybe back to search if search params exist?
// Simplest behavior: clear selection
this.router.transitionTo('index');
} else if (
this.router.currentRouteName === 'search' ||
this.router.currentRouteName === 'place'
) {
this.mapUi.clearSelection();
this.mapUi.hideSidebar();
}
}

View File

@@ -79,6 +79,7 @@ export default class PlaceTemplate extends Component {
if (place === null) {
// If we have an active search context, return to it (UP navigation)
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
this.mapUi.showSidebar();
this.router.transitionTo('search', {
queryParams: this.mapUi.currentSearch,
});
@@ -88,23 +89,26 @@ export default class PlaceTemplate extends Component {
}
} else {
// If a place is selected (unlikely in this view, but possible if we add related links)
this.mapUi.showSidebar();
this.router.transitionTo('place', place);
}
}
@action
close() {
// Clear search results so we don't fall back to the list
this.router.transitionTo('index');
this.mapUi.clearSelection();
this.mapUi.hideSidebar();
}
<template>
<PlacesSidebar
@selectedPlace={{this.place}}
@onClose={{this.close}}
@onSelect={{this.navigateBack}}
@onBookmarkChange={{this.refreshMap}}
@onUpdate={{this.handleUpdate}}
/>
{{#if this.mapUi.isSidebarVisible}}
<PlacesSidebar
@selectedPlace={{this.place}}
@onClose={{this.close}}
@onSelect={{this.navigateBack}}
@onBookmarkChange={{this.refreshMap}}
@onUpdate={{this.handleUpdate}}
/>
{{/if}}
</template>
}

View File

@@ -56,28 +56,30 @@ export default class PlaceNewTemplate extends Component {
}
<template>
<div class="sidebar">
<div class="sidebar-header">
<h2><Icon @name="plus-circle" @size={{20}} @color="#ea4335" />
New Place</h2>
<button type="button" class="close-btn" {{on "click" this.close}}><Icon
@name="x"
@size={{20}}
@color="#333"
/></button>
</div>
{{#if this.mapUi.isSidebarVisible}}
<div class="sidebar">
<div class="sidebar-header">
<h2><Icon @name="plus-circle" @size={{20}} @color="#ea4335" />
New Place</h2>
<button
type="button"
class="close-btn"
{{on "click" this.close}}
><Icon @name="x" @size={{20}} @color="#333" /></button>
</div>
<div class="sidebar-content">
<p class="helper-text">
Drag the map to position the crosshair.
</p>
<div class="sidebar-content">
<p class="helper-text">
Drag the map to position the crosshair.
</p>
<PlaceEditForm
@place={{this.initialPlace}}
@onSave={{this.savePlace}}
@onCancel={{this.close}}
/>
<PlaceEditForm
@place={{this.initialPlace}}
@onSave={{this.savePlace}}
@onCancel={{this.close}}
/>
</div>
</div>
</div>
{{/if}}
</template>
}

View File

@@ -11,6 +11,7 @@ export default class SearchTemplate extends Component {
selectPlace(place) {
if (place) {
this.mapUi.returnToSearch = true;
this.mapUi.showSidebar();
// We don't need to manually set currentSearch here because
// it was already set in the route's setupController
this.router.transitionTo('place', place);
@@ -19,14 +20,16 @@ export default class SearchTemplate extends Component {
@action
close() {
this.router.transitionTo('index');
this.mapUi.hideSidebar();
}
<template>
<PlacesSidebar
@places={{@model}}
@onSelect={{this.selectPlace}}
@onClose={{this.close}}
/>
{{#if this.mapUi.isSidebarVisible}}
<PlacesSidebar
@places={{@model}}
@onSelect={{this.selectPlace}}
@onClose={{this.close}}
/>
{{/if}}
</template>
}