Refactoring: split 'ThemeViewState' into many classes

This commit is contained in:
Pieter Vander Vennet 2025-01-23 05:01:55 +01:00
parent 2b858bd2aa
commit dbcbf2787d
34 changed files with 1503 additions and 1227 deletions

View file

@ -17,7 +17,6 @@ import FeatureSwitchState from "./FeatureSwitchState"
import Constants from "../../Models/Constants"
import { QueryParameters } from "../Web/QueryParameters"
import { ThemeMetaTagging } from "./UserSettingsMetaTagging"
import { MapProperties } from "../../Models/MapProperties"
import Showdown from "showdown"
import { LocalStorageSource } from "../Web/LocalStorageSource"
import { GeocodeResult } from "../Search/GeocodingProvider"
@ -53,7 +52,7 @@ export class OptionallySyncedHistory<T> {
))
this.syncPreference.addCallback((syncmode) => {
if (syncmode === "sync") {
let list = [...thisSession.data, ...synced.data].slice(0, maxHistory)
const list = [...thisSession.data, ...synced.data].slice(0, maxHistory)
if (this._isSame) {
for (let i = 0; i < list.length; i++) {
for (let j = i + 1; j < list.length; j++) {
@ -178,7 +177,6 @@ export default class UserRelatedState {
* Note: these are linked via OsmConnection.preferences which exports all preferences as UIEventSource
*/
public readonly preferencesAsTags: UIEventSource<Record<string, string>>
private readonly _mapProperties: MapProperties
public readonly recentlyVisitedThemes: OptionallySyncedHistory<string>
public readonly recentlyVisitedSearch: OptionallySyncedHistory<GeocodeResult>
@ -187,10 +185,9 @@ export default class UserRelatedState {
osmConnection: OsmConnection,
layout?: ThemeConfig,
featureSwitches?: FeatureSwitchState,
mapProperties?: MapProperties
currentRasterLayer?: Store<{ properties: { id: string } }>
) {
this.osmConnection = osmConnection
this._mapProperties = mapProperties
this.showAllQuestionsAtOnce = UIEventSource.asBoolean(
this.osmConnection.getPreference("show-all-questions", "false")
@ -224,7 +221,7 @@ export default class UserRelatedState {
this.translationMode = this.initTranslationMode()
this.homeLocation = this.initHomeLocation()
this.preferencesAsTags = this.initAmendedPrefs(layout, featureSwitches)
this.preferencesAsTags = this.initAmendedPrefs(layout, featureSwitches, currentRasterLayer)
this.recentlyVisitedThemes = new OptionallySyncedHistory<string>(
"theme",
@ -405,7 +402,8 @@ export default class UserRelatedState {
* */
private initAmendedPrefs(
layout?: ThemeConfig,
featureSwitches?: FeatureSwitchState
featureSwitches?: FeatureSwitchState,
currentRasterLayer?: Store<{ properties: { id: string } }>
): UIEventSource<Record<string, string>> {
const amendedPrefs = new UIEventSource<Record<string, string>>({
_theme: layout?.id,
@ -541,7 +539,7 @@ export default class UserRelatedState {
if (tags[key] === null) {
continue
}
let pref = this.osmConnection.GetPreference(key, undefined, { prefix: "" })
const pref = this.osmConnection.GetPreference(key, undefined, { prefix: "" })
pref.set(tags[key])
}
@ -560,7 +558,7 @@ export default class UserRelatedState {
}
}
this._mapProperties?.rasterLayer?.addCallbackAndRun((l) => {
currentRasterLayer?.addCallbackAndRun((l) => {
amendedPrefs.data["__current_background"] = l?.properties?.id
amendedPrefs.ping()
})