From 12e746c2a3f305ebdb5731a0b42d0054b81b34f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Thu, 17 Sep 2026 23:01:07 +0200 Subject: [PATCH] Clear search with no results when closing drawer --- app/controllers/search.js | 12 ++++++++ app/routes/search.js | 4 --- app/templates/application.gjs | 3 ++ app/templates/search.gjs | 10 +++++-- tests/acceptance/navigation-test.js | 43 ++++++++++++++++++++++++++++ tests/acceptance/search-test.js | 44 ++++++++++++++++++++++++++++- 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/app/controllers/search.js b/app/controllers/search.js index 8625c07..fd16661 100644 --- a/app/controllers/search.js +++ b/app/controllers/search.js @@ -176,6 +176,18 @@ export default class SearchController extends Controller { return saved || p; }); + // A search with results is a restorable context (e.g. for "up" navigation + // from place details). Empty searches are intentionally not restorable, so + // they don't reopen an invisible "no results" drawer later on. + if (pois.length > 0) { + this.mapUi.currentSearch = { + q: params.q, + category: params.category, + lat: params.lat, + lon: params.lon, + }; + } + const targetName = params.selected || params.q; if (targetName && pois.length > 0) { diff --git a/app/routes/search.js b/app/routes/search.js index bbf6e69..94c6a27 100644 --- a/app/routes/search.js +++ b/app/routes/search.js @@ -24,10 +24,6 @@ export default class SearchRoute extends Route { // Trigger the background task to fetch results controller.fetchResultsTask.perform(model); - - // Store current search params to allow "Up" navigation from place details - const { q, category, lat, lon } = this.paramsFor('search'); - this.mapUi.currentSearch = { q, category, lat, lon }; } resetController(controller, isExiting) { diff --git a/app/templates/application.gjs b/app/templates/application.gjs index ec78751..a70167a 100644 --- a/app/templates/application.gjs +++ b/app/templates/application.gjs @@ -72,6 +72,9 @@ export default class ApplicationComponent extends Component { } else { this.router.transitionTo('index'); } + } else if (name === 'search' && this.mapUi.searchResults.length === 0) { + // An empty search has no markers worth keeping, so clear the route + this.router.replaceWith('index'); } } } diff --git a/app/templates/search.gjs b/app/templates/search.gjs index 7c4268f..c43617c 100644 --- a/app/templates/search.gjs +++ b/app/templates/search.gjs @@ -18,14 +18,20 @@ export default class SearchTemplate extends Component { this.mapUi.showSidebar(); this.mapUi.preventNextZoom = true; // We don't need to manually set currentSearch here because - // it was already set in the route's setupController + // it was already set in the search controller this.router.transitionTo('place', place); } } @action close() { - this.mapUi.hideSidebar(); + // With no results there is nothing to keep around (no map markers), so + // dismissing the drawer clears the search route entirely. + if (this.mapUi.searchResults.length === 0) { + this.router.replaceWith('index'); + } else { + this.mapUi.hideSidebar(); + } }