From f82a79772046af596d1910cc24f1d713321ea594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sat, 6 Jun 2026 12:00:48 +0400 Subject: [PATCH] Include list names in search results for saved places --- app/components/search-box.gjs | 35 +++++++++++++------ .../components/search-box-test.gjs | 10 ++++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/components/search-box.gjs b/app/components/search-box.gjs index 88310b8..f7f0ef3 100644 --- a/app/components/search-box.gjs +++ b/app/components/search-box.gjs @@ -51,6 +51,29 @@ export default class SearchBoxComponent extends Component { this.searchTask.perform(value); } + formatSavedPlace(place) { + const listNames = (place._listIds || []) + .map((id) => this.storage.lists?.find((l) => l.id === id)?.title) + .filter(Boolean) + .join(', '); + + const description = listNames + ? `Saved place (${listNames})` + : 'Saved place'; + + return { + source: 'saved', + id: place.id, + title: place.title, + icon: 'bookmark', + description, + osmId: place.osmId, + osmType: place.osmType, + lat: place.lat, + lon: place.lon, + }; + } + searchTask = task({ restartable: true }, async (term) => { await timeout(300); @@ -82,17 +105,7 @@ export default class SearchBoxComponent extends Component { if (q.length >= 3) { savedMatches = this.storage.savedPlaces .filter((p) => p.title && p.title.toLowerCase().includes(q)) - .map((p) => ({ - source: 'saved', - id: p.id, - title: p.title, - icon: 'bookmark', - description: 'Saved place', - osmId: p.osmId, - osmType: p.osmType, - lat: p.lat, - lon: p.lon, - })); + .map((p) => this.formatSavedPlace(p)); } const results = await this.photon.search(query, lat, lon); diff --git a/tests/integration/components/search-box-test.gjs b/tests/integration/components/search-box-test.gjs index 58857e2..fb24b5e 100644 --- a/tests/integration/components/search-box-test.gjs +++ b/tests/integration/components/search-box-test.gjs @@ -249,6 +249,7 @@ module('Integration | Component | search-box', function (hooks) { // Mock Storage Service class MockStorageService extends Service { + lists = [{ id: 'favs', title: 'Favorites' }]; savedPlaces = [ { title: 'Awesome Coffee', @@ -256,6 +257,7 @@ module('Integration | Component | search-box', function (hooks) { lon: 13.4, osmId: '999', osmType: 'node', + _listIds: ['favs'], }, ]; } @@ -355,6 +357,7 @@ module('Integration | Component | search-box', function (hooks) { // Mock Storage Service class MockStorageService extends Service { + lists = [{ id: 'favs', title: 'Favorites' }]; savedPlaces = [ { title: 'Awesome Coffee', @@ -362,6 +365,7 @@ module('Integration | Component | search-box', function (hooks) { lon: 13.4, osmId: '999', osmType: 'node', + _listIds: ['favs'], }, ]; } @@ -430,6 +434,12 @@ module('Integration | Component | search-box', function (hooks) { resultItems.some((item) => item.textContent.includes('Awesome Coffee')), 'Saved place is now shown' ); + assert.ok( + resultItems.some((item) => + item.textContent.includes('Saved place (Favorites)') + ), + 'List names are appended to the description' + ); }); test('it navigates to internal ID for custom saved places without an OSM ID', async function (assert) {