Skip to content

Commit

Permalink
Rework preferences handling, improve search
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Sep 10, 2024
1 parent b45cfca commit 4085bbc
Show file tree
Hide file tree
Showing 19 changed files with 420 additions and 516 deletions.
16 changes: 8 additions & 8 deletions assets/layers/usersettings/usersettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,20 +838,20 @@
},
"mappings": [
{
"if": "mapcomplete-theme-history=sync",
"alsoShowIf": "mapcomplete-theme-history=",
"if": "mapcomplete-preference-theme-history=sync",
"alsoShowIf": "mapcomplete-preference-theme-history=",
"then": {
"en": "Save the visited thematic maps and sync them via openstreetmap.org. OpenStreetMap and all apps you use can see this history"
}
},
{
"if": "mapcomplete-theme-history=local",
"if": "mapcomplete-preference-theme-history=local",
"then": {
"en": "Save the visited thematic maps on my device"
}
},
{
"if": "mapcomplete-theme-history=no",
"if": "mapcomplete-preference-theme-history=no",
"then": {
"en": "Don't save visited thematic maps"
}
Expand All @@ -868,20 +868,20 @@
},
"mappings": [
{
"if": "mapcomplete-search-history=sync",
"alsoShowIf": "mapcomplete-search-history=",
"if": "mapcomplete-preference-search-history=sync",
"alsoShowIf": "mapcomplete-preference-search-history=",
"then": {
"en": "Save the locations you search for and inspect and sync them via openstreetmap.org. OpenStreetMap and all apps you use can see this history"
}
},
{
"if": "mapcomplete-search-history=local",
"if": "mapcomplete-preference-search-history=local",
"then": {
"en": "Save the locations you search for and inspect on my device"
}
},
{
"if": "mapcomplete-search-history=no",
"if": "mapcomplete-preference-search-history=no",
"then": {
"en": "Don't save the locations you search for and inspect "
}
Expand Down
2 changes: 1 addition & 1 deletion src/Logic/FeatureSource/Sources/FavouritesFeatureSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class FavouritesFeatureSource extends StaticFeatureSource {

constructor(state: SpecialVisualizationState) {
const features: Store<Feature[]> = Stores.ListStabilized(
state.osmConnection.preferencesHandler.preferences.map((prefs) => {
state.osmConnection.preferencesHandler.allPreferences.map((prefs) => {
const feats: Feature[] = []
const allIds = new Set<string>()
for (const key in prefs) {
Expand Down
80 changes: 0 additions & 80 deletions src/Logic/Geocoding/RecentSearch.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/Logic/Geocoding/ThemeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import GeocodingProvider, { GeocodingOptions, SearchResult } from "./GeocodingProvider"
import * as themeOverview from "../../assets/generated/theme_overview.json"
import { MinimalLayoutInformation } from "../../Models/ThemeConfig/LayoutConfig"
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
import MoreScreen from "../../UI/BigComponents/MoreScreen"
import { ImmutableStore, Store } from "../UIEventSource"
import UserRelatedState from "../State/UserRelatedState"

export default class ThemeSearch implements GeocodingProvider {

private static allThemes: MinimalLayoutInformation[] = (themeOverview["default"] ?? themeOverview)
private readonly _state: SpecialVisualizationState
private readonly _knownHiddenThemes: Store<Set<string>>
private readonly _suggestionLimit: number
Expand All @@ -18,7 +17,7 @@ export default class ThemeSearch implements GeocodingProvider {
this._state = state
this._layersToIgnore = state.layout.layers.map(l => l.id)
this._suggestionLimit = suggestionLimit
this._knownHiddenThemes = MoreScreen.knownHiddenThemes(this._state.osmConnection)
this._knownHiddenThemes = UserRelatedState.initDiscoveredHiddenThemes(this._state.osmConnection).map(list => new Set(list))
this._otherThemes = MoreScreen.officialThemes.themes
.filter(th => th.id !== state.layout.id)
}
Expand All @@ -45,7 +44,6 @@ export default class ThemeSearch implements GeocodingProvider {
return []
}
const sorted = MoreScreen.sortedByLowest(query, this._otherThemes, this._layersToIgnore)
console.log(">>>", sorted)
return sorted
.filter(sorted => sorted.lowest < 2)
.map(th => th.theme)
Expand Down
4 changes: 1 addition & 3 deletions src/Logic/Osm/OsmConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class OsmConnection {
this.preferencesHandler = new OsmPreferences(this.auth, this, this.fakeUser)

if (options.oauth_token?.data !== undefined) {
console.log(options.oauth_token.data)
this.auth.bootstrapToken(options.oauth_token.data, (err, result) => {
console.log("Bootstrap token called back", err, result)
this.AttemptLogin()
Expand All @@ -160,10 +159,10 @@ export class OsmConnection {
key: string,
defaultValue: string = undefined,
options?: {
documentation?: string
prefix?: string
}
): UIEventSource<T | undefined> {
options ??= {prefix: "mapcomplete-"}
return <UIEventSource<T>>this.preferencesHandler.GetPreference(key, defaultValue, options)
}

Expand All @@ -183,7 +182,6 @@ export class OsmConnection {
this.userDetails.ping()
console.log("Logged out")
this.loadingStatus.setData("not-attempted")
this.preferencesHandler.preferences.setData(undefined)
}

/**
Expand Down
Loading

0 comments on commit 4085bbc

Please sign in to comment.