diff --git a/src/Logic/Geocoding/RecentSearch.ts b/src/Logic/Geocoding/RecentSearch.ts index 5af34fa2a..f9f7732ed 100644 --- a/src/Logic/Geocoding/RecentSearch.ts +++ b/src/Logic/Geocoding/RecentSearch.ts @@ -8,13 +8,11 @@ import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" export class RecentSearch { - private readonly _seenThisSession: UIEventSource - public readonly seenThisSession: Store + public readonly seenThisSession: UIEventSource constructor(state: { layout: LayoutConfig, osmConnection: OsmConnection, selectedElement: Store }) { const prefs = state.osmConnection.preferencesHandler.GetLongPreference("previous-searches") - this._seenThisSession = new UIEventSource([])//UIEventSource.asObject(prefs, []) - this.seenThisSession = this._seenThisSession + this.seenThisSession = new UIEventSource([])//UIEventSource.asObject(prefs, []) prefs.addCallbackAndRunD(pref => { if (pref === "") { @@ -24,7 +22,7 @@ export class RecentSearch { const simpleArr = JSON.parse(pref) if (simpleArr.length > 0) { - this._seenThisSession.set(simpleArr) + this.seenThisSession.set(simpleArr) return true } } catch (e) { @@ -72,17 +70,10 @@ export class RecentSearch { } addSelected(entry: GeocodeResult) { - const arr = [...(this.seenThisSession.data ?? []).slice(0, 20), entry] + const id = entry.osm_type+entry.osm_id + const arr = [...(this.seenThisSession.data.reverse() ?? []).slice(0, 5)] + .filter(e => e.osm_type+e.osm_id !== id) - const seenIds = new Set() - for (let i = arr.length - 1; i >= 0; i--) { - const id = arr[i].osm_type + arr[i].osm_id - if (seenIds.has(id)) { - arr.splice(i, 1) - } else { - seenIds.add(id) - } - } - this._seenThisSession.set(arr) + this.seenThisSession.set([entry, ...arr]) } } diff --git a/src/Logic/Geocoding/ThemeSearch.ts b/src/Logic/Geocoding/ThemeSearch.ts index 254c8ba82..6428a3e61 100644 --- a/src/Logic/Geocoding/ThemeSearch.ts +++ b/src/Logic/Geocoding/ThemeSearch.ts @@ -47,6 +47,7 @@ export default class ThemeSearch implements GeocodingProvider { const sorted = MoreScreen.sortedByLowest(query, this._otherThemes, this._layersToIgnore) console.log(">>>", sorted) return sorted + .filter(sorted => sorted.lowest < 2) .map(th => th.theme) .filter(th => !th.hideFromOverview || this._knownHiddenThemes.data.has(th.id)) .slice(0, limit) diff --git a/src/Logic/State/UserRelatedState.ts b/src/Logic/State/UserRelatedState.ts index a6afd4fb7..90cc0645d 100644 --- a/src/Logic/State/UserRelatedState.ts +++ b/src/Logic/State/UserRelatedState.ts @@ -80,8 +80,7 @@ export default class UserRelatedState { public readonly preferencesAsTags: UIEventSource> private readonly _mapProperties: MapProperties - private readonly _recentlyVisitedThemes: UIEventSource - public readonly recentlyVisitedThemes: Store + public readonly recentlyVisitedThemes: UIEventSource constructor( @@ -138,11 +137,10 @@ export default class UserRelatedState { this.preferencesAsTags = this.initAmendedPrefs(layout, featureSwitches) const prefs = this.osmConnection - this._recentlyVisitedThemes = UIEventSource.asObject(prefs.GetLongPreference("recently-visited-themes"), []) - this.recentlyVisitedThemes = this._recentlyVisitedThemes + this.recentlyVisitedThemes = UIEventSource.asObject(prefs.GetLongPreference("recently-visited-themes"), []) if (layout) { const osmConn = this.osmConnection - const recentlyVisited = this._recentlyVisitedThemes + const recentlyVisited = this.recentlyVisitedThemes function update() { if (!osmConn.isLoggedIn.data) { @@ -158,7 +156,7 @@ export default class UserRelatedState { } - this._recentlyVisitedThemes.addCallbackAndRun(() => update()) + this.recentlyVisitedThemes.addCallbackAndRun(() => update()) this.osmConnection.isLoggedIn.addCallbackAndRun(() => update()) } diff --git a/src/UI/Search/GeocodeResult.svelte b/src/UI/Search/GeocodeResult.svelte index da1c24b0b..d7fe871b9 100644 --- a/src/UI/Search/GeocodeResult.svelte +++ b/src/UI/Search/GeocodeResult.svelte @@ -47,7 +47,7 @@ if (entry.feature?.properties?.id) { state.selectedElement.set(entry.feature) } - state.recentlySearched.addSelected(entry) + state.searchState.recentlySearched.addSelected(entry) dispatch("select") } diff --git a/src/UI/Search/SearchResults.svelte b/src/UI/Search/SearchResults.svelte index a64d0bf8d..8c5d0e9ce 100644 --- a/src/UI/Search/SearchResults.svelte +++ b/src/UI/Search/SearchResults.svelte @@ -1,5 +1,5 @@