forked from MapComplete/MapComplete
Fix(reviews): correctly handle fallbackname due to proper caching, add correct ratings-bar to toilets
This commit is contained in:
parent
b83b470508
commit
d1526991eb
5 changed files with 59 additions and 14 deletions
assets/layers/toilet
src
|
@ -73,6 +73,17 @@
|
|||
"cy": "Toiled"
|
||||
}
|
||||
},
|
||||
"titleIcons": [
|
||||
"defaults",
|
||||
{
|
||||
"render": {
|
||||
"special": {
|
||||
"type": "rating",
|
||||
"fallbackName": "toilets"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"pointRendering": [
|
||||
{
|
||||
"iconBadges": [
|
||||
|
|
|
@ -158,27 +158,33 @@ export default class FeatureReviews {
|
|||
private readonly _name: Store<string>
|
||||
private readonly _identity: MangroveIdentity
|
||||
private readonly _testmode: Store<boolean>
|
||||
public loadingAllowed: UIEventSource<boolean | null>
|
||||
public readonly loadingAllowed: UIEventSource<boolean | null>
|
||||
private readonly _options: Readonly<{
|
||||
nameKey?: "name" | string;
|
||||
fallbackName?: string;
|
||||
uncertaintyRadius?: number
|
||||
}>
|
||||
|
||||
private constructor(
|
||||
feature: Feature,
|
||||
tagsSource: UIEventSource<Record<string, string>>,
|
||||
mangroveIdentity: MangroveIdentity,
|
||||
options?: {
|
||||
options?: Readonly<{
|
||||
nameKey?: "name" | string
|
||||
fallbackName?: string
|
||||
uncertaintyRadius?: number
|
||||
},
|
||||
}>,
|
||||
testmode?: Store<boolean>,
|
||||
loadingAllowed?: UIEventSource<boolean | null>
|
||||
) {
|
||||
console.trace(">>> Creating FeatureReviews", options)
|
||||
this.loadingAllowed = loadingAllowed
|
||||
const centerLonLat = GeoOperations.centerpointCoordinates(feature)
|
||||
;[this._lon, this._lat] = centerLonLat
|
||||
this._identity = mangroveIdentity
|
||||
this._testmode = testmode ?? new ImmutableStore(false)
|
||||
const nameKey = options?.nameKey ?? "name"
|
||||
|
||||
this._options = options
|
||||
if (options.uncertaintyRadius) {
|
||||
this._uncertainty = options.uncertaintyRadius
|
||||
} else if (feature.geometry.type === "Point") {
|
||||
|
@ -209,7 +215,16 @@ export default class FeatureReviews {
|
|||
|
||||
this._uncertainty = maxDistance
|
||||
}
|
||||
this._name = tagsSource.map((tags) => tags[nameKey] ?? options?.fallbackName)
|
||||
this._name = tagsSource.map((tags) => {
|
||||
const defaultName = tags[nameKey]
|
||||
console.trace(">>>", options, defaultName)
|
||||
if (defaultName && defaultName !== "") {
|
||||
console.log("Using default name:", defaultName, "fallback:", options.fallbackName)
|
||||
return defaultName
|
||||
}
|
||||
console.trace("Using fallback name", options?.fallbackName, options)
|
||||
return options?.fallbackName
|
||||
})
|
||||
|
||||
this.subjectUri = this.ConstructSubjectUri()
|
||||
|
||||
|
@ -265,6 +280,14 @@ export default class FeatureReviews {
|
|||
* @param tagsSource Dynamic tags of the feature
|
||||
* @param mangroveIdentity Identity with which new REviews will be mad
|
||||
* @param options If options.nameKey is given, this key will be used as subject to fetch reviews
|
||||
*
|
||||
* const f = {type:"Feature", properties: {id: "node/1234"}, geometry: {type:"Point", coordinates: [12,13]}}
|
||||
* const reviews = FeatureReviews.construct(f, new UIEventSource({}), undefined, {fallbackName: "toilets"}, undefined)
|
||||
* reviews.subjectUri.data // => "geo:13,12?u=10&q=toilets"
|
||||
*
|
||||
* const f = {type:"Feature", properties: {id: "node/1234"}, geometry: {type:"Point", coordinates: [12,13]}}
|
||||
* const reviews = FeatureReviews.construct(f, new UIEventSource({name: ""}), undefined, {fallbackName: "toilets"}, undefined)
|
||||
* reviews.subjectUri.data // => "geo:13,12?u=10&q=toilets"
|
||||
*/
|
||||
public static construct(
|
||||
feature: Feature,
|
||||
|
@ -275,20 +298,19 @@ export default class FeatureReviews {
|
|||
fallbackName?: string
|
||||
uncertaintyRadius?: number
|
||||
},
|
||||
state: SpecialVisualizationState
|
||||
state?: SpecialVisualizationState
|
||||
): FeatureReviews {
|
||||
const key = feature.properties.id
|
||||
const key = feature.properties.id + ";" + (options?.nameKey ?? "") + ";" + (options?.fallbackName ?? "")
|
||||
const cached = FeatureReviews._featureReviewsCache[key]
|
||||
if (cached !== undefined) {
|
||||
return cached
|
||||
}
|
||||
const themeIsSensitive = state.theme?.enableMorePrivacy
|
||||
const settings = state.osmConnection.getPreference<"always" | "yes" | "ask" | "hidden">(
|
||||
const themeIsSensitive = state?.theme?.enableMorePrivacy ?? false
|
||||
const settings = state?.osmConnection?.getPreference<"always" | "yes" | "ask" | "hidden">(
|
||||
"reviews-allowed"
|
||||
)
|
||||
) ?? new ImmutableStore("yes");
|
||||
const loadingAllowed = new UIEventSource(false)
|
||||
settings.addCallbackAndRun((s) => {
|
||||
console.log("Reviews allowed is", s)
|
||||
if (s === "hidden") {
|
||||
loadingAllowed.set(null)
|
||||
return
|
||||
|
@ -308,7 +330,7 @@ export default class FeatureReviews {
|
|||
tagsSource,
|
||||
mangroveIdentity,
|
||||
options,
|
||||
state.featureSwitchIsTesting,
|
||||
state?.featureSwitchIsTesting,
|
||||
loadingAllowed
|
||||
)
|
||||
FeatureReviews._featureReviewsCache[key] = featureReviews
|
||||
|
|
|
@ -148,8 +148,7 @@ class SingleBackgroundHandler {
|
|||
const styleToSet = background.style ?? background.url
|
||||
map.setStyle(styleToSet)
|
||||
this.awaitStyleIsLoaded().then(() => {
|
||||
console.log("UPDATING")
|
||||
this._languageSupport.update()
|
||||
this._languageSupport?.update()
|
||||
})
|
||||
} else {
|
||||
map.addLayer(
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
reviews.reviews.addCallbackAndRunD((r) => {
|
||||
_reviews = Utils.NoNull(r)
|
||||
})
|
||||
let test = state.featureSwitches.featureSwitchIsTesting
|
||||
let debug = state.featureSwitches.featureSwitchIsDebugging
|
||||
let subject = reviews.subjectUri
|
||||
</script>
|
||||
|
||||
<ReviewPrivacyShield {reviews} guistate={state.guistate}>
|
||||
|
@ -38,5 +41,8 @@
|
|||
<div class="flex justify-end">
|
||||
<Tr cls="text-sm subtle" t={Translations.t.reviews.attribution} />
|
||||
</div>
|
||||
{#if $debug || $test}
|
||||
<span class="self-end">{$subject}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</ReviewPrivacyShield>
|
||||
|
|
|
@ -70,6 +70,10 @@
|
|||
}
|
||||
_state = "done"
|
||||
}
|
||||
|
||||
let test = state.featureSwitches.featureSwitchIsTesting
|
||||
let debug = state.featureSwitches.featureSwitchIsDebugging
|
||||
let subject = reviews.subjectUri
|
||||
</script>
|
||||
|
||||
<ReviewPrivacyShield hiddenIfNotAllowed {reviews} guistate={state.guistate}>
|
||||
|
@ -158,6 +162,9 @@
|
|||
|
||||
<Tr cls="subtle mt-4" t={t.tos} />
|
||||
{/if}
|
||||
{#if $debug || $test}
|
||||
<span class="self-end subtle">{$subject}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</ReviewPrivacyShield>
|
||||
|
|
Loading…
Add table
Reference in a new issue