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
|
@ -73,6 +73,17 @@
|
||||||
"cy": "Toiled"
|
"cy": "Toiled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"titleIcons": [
|
||||||
|
"defaults",
|
||||||
|
{
|
||||||
|
"render": {
|
||||||
|
"special": {
|
||||||
|
"type": "rating",
|
||||||
|
"fallbackName": "toilets"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"pointRendering": [
|
"pointRendering": [
|
||||||
{
|
{
|
||||||
"iconBadges": [
|
"iconBadges": [
|
||||||
|
|
|
@ -158,27 +158,33 @@ export default class FeatureReviews {
|
||||||
private readonly _name: Store<string>
|
private readonly _name: Store<string>
|
||||||
private readonly _identity: MangroveIdentity
|
private readonly _identity: MangroveIdentity
|
||||||
private readonly _testmode: Store<boolean>
|
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(
|
private constructor(
|
||||||
feature: Feature,
|
feature: Feature,
|
||||||
tagsSource: UIEventSource<Record<string, string>>,
|
tagsSource: UIEventSource<Record<string, string>>,
|
||||||
mangroveIdentity: MangroveIdentity,
|
mangroveIdentity: MangroveIdentity,
|
||||||
options?: {
|
options?: Readonly<{
|
||||||
nameKey?: "name" | string
|
nameKey?: "name" | string
|
||||||
fallbackName?: string
|
fallbackName?: string
|
||||||
uncertaintyRadius?: number
|
uncertaintyRadius?: number
|
||||||
},
|
}>,
|
||||||
testmode?: Store<boolean>,
|
testmode?: Store<boolean>,
|
||||||
loadingAllowed?: UIEventSource<boolean | null>
|
loadingAllowed?: UIEventSource<boolean | null>
|
||||||
) {
|
) {
|
||||||
|
console.trace(">>> Creating FeatureReviews", options)
|
||||||
this.loadingAllowed = loadingAllowed
|
this.loadingAllowed = loadingAllowed
|
||||||
const centerLonLat = GeoOperations.centerpointCoordinates(feature)
|
const centerLonLat = GeoOperations.centerpointCoordinates(feature)
|
||||||
;[this._lon, this._lat] = centerLonLat
|
;[this._lon, this._lat] = centerLonLat
|
||||||
this._identity = mangroveIdentity
|
this._identity = mangroveIdentity
|
||||||
this._testmode = testmode ?? new ImmutableStore(false)
|
this._testmode = testmode ?? new ImmutableStore(false)
|
||||||
const nameKey = options?.nameKey ?? "name"
|
const nameKey = options?.nameKey ?? "name"
|
||||||
|
this._options = options
|
||||||
if (options.uncertaintyRadius) {
|
if (options.uncertaintyRadius) {
|
||||||
this._uncertainty = options.uncertaintyRadius
|
this._uncertainty = options.uncertaintyRadius
|
||||||
} else if (feature.geometry.type === "Point") {
|
} else if (feature.geometry.type === "Point") {
|
||||||
|
@ -209,7 +215,16 @@ export default class FeatureReviews {
|
||||||
|
|
||||||
this._uncertainty = maxDistance
|
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()
|
this.subjectUri = this.ConstructSubjectUri()
|
||||||
|
|
||||||
|
@ -265,6 +280,14 @@ export default class FeatureReviews {
|
||||||
* @param tagsSource Dynamic tags of the feature
|
* @param tagsSource Dynamic tags of the feature
|
||||||
* @param mangroveIdentity Identity with which new REviews will be mad
|
* @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
|
* @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(
|
public static construct(
|
||||||
feature: Feature,
|
feature: Feature,
|
||||||
|
@ -275,20 +298,19 @@ export default class FeatureReviews {
|
||||||
fallbackName?: string
|
fallbackName?: string
|
||||||
uncertaintyRadius?: number
|
uncertaintyRadius?: number
|
||||||
},
|
},
|
||||||
state: SpecialVisualizationState
|
state?: SpecialVisualizationState
|
||||||
): FeatureReviews {
|
): FeatureReviews {
|
||||||
const key = feature.properties.id
|
const key = feature.properties.id + ";" + (options?.nameKey ?? "") + ";" + (options?.fallbackName ?? "")
|
||||||
const cached = FeatureReviews._featureReviewsCache[key]
|
const cached = FeatureReviews._featureReviewsCache[key]
|
||||||
if (cached !== undefined) {
|
if (cached !== undefined) {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
const themeIsSensitive = state.theme?.enableMorePrivacy
|
const themeIsSensitive = state?.theme?.enableMorePrivacy ?? false
|
||||||
const settings = state.osmConnection.getPreference<"always" | "yes" | "ask" | "hidden">(
|
const settings = state?.osmConnection?.getPreference<"always" | "yes" | "ask" | "hidden">(
|
||||||
"reviews-allowed"
|
"reviews-allowed"
|
||||||
)
|
) ?? new ImmutableStore("yes");
|
||||||
const loadingAllowed = new UIEventSource(false)
|
const loadingAllowed = new UIEventSource(false)
|
||||||
settings.addCallbackAndRun((s) => {
|
settings.addCallbackAndRun((s) => {
|
||||||
console.log("Reviews allowed is", s)
|
|
||||||
if (s === "hidden") {
|
if (s === "hidden") {
|
||||||
loadingAllowed.set(null)
|
loadingAllowed.set(null)
|
||||||
return
|
return
|
||||||
|
@ -308,7 +330,7 @@ export default class FeatureReviews {
|
||||||
tagsSource,
|
tagsSource,
|
||||||
mangroveIdentity,
|
mangroveIdentity,
|
||||||
options,
|
options,
|
||||||
state.featureSwitchIsTesting,
|
state?.featureSwitchIsTesting,
|
||||||
loadingAllowed
|
loadingAllowed
|
||||||
)
|
)
|
||||||
FeatureReviews._featureReviewsCache[key] = featureReviews
|
FeatureReviews._featureReviewsCache[key] = featureReviews
|
||||||
|
|
|
@ -148,8 +148,7 @@ class SingleBackgroundHandler {
|
||||||
const styleToSet = background.style ?? background.url
|
const styleToSet = background.style ?? background.url
|
||||||
map.setStyle(styleToSet)
|
map.setStyle(styleToSet)
|
||||||
this.awaitStyleIsLoaded().then(() => {
|
this.awaitStyleIsLoaded().then(() => {
|
||||||
console.log("UPDATING")
|
this._languageSupport?.update()
|
||||||
this._languageSupport.update()
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
map.addLayer(
|
map.addLayer(
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
reviews.reviews.addCallbackAndRunD((r) => {
|
reviews.reviews.addCallbackAndRunD((r) => {
|
||||||
_reviews = Utils.NoNull(r)
|
_reviews = Utils.NoNull(r)
|
||||||
})
|
})
|
||||||
|
let test = state.featureSwitches.featureSwitchIsTesting
|
||||||
|
let debug = state.featureSwitches.featureSwitchIsDebugging
|
||||||
|
let subject = reviews.subjectUri
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ReviewPrivacyShield {reviews} guistate={state.guistate}>
|
<ReviewPrivacyShield {reviews} guistate={state.guistate}>
|
||||||
|
@ -38,5 +41,8 @@
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<Tr cls="text-sm subtle" t={Translations.t.reviews.attribution} />
|
<Tr cls="text-sm subtle" t={Translations.t.reviews.attribution} />
|
||||||
</div>
|
</div>
|
||||||
|
{#if $debug || $test}
|
||||||
|
<span class="self-end">{$subject}</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</ReviewPrivacyShield>
|
</ReviewPrivacyShield>
|
||||||
|
|
|
@ -70,6 +70,10 @@
|
||||||
}
|
}
|
||||||
_state = "done"
|
_state = "done"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let test = state.featureSwitches.featureSwitchIsTesting
|
||||||
|
let debug = state.featureSwitches.featureSwitchIsDebugging
|
||||||
|
let subject = reviews.subjectUri
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ReviewPrivacyShield hiddenIfNotAllowed {reviews} guistate={state.guistate}>
|
<ReviewPrivacyShield hiddenIfNotAllowed {reviews} guistate={state.guistate}>
|
||||||
|
@ -158,6 +162,9 @@
|
||||||
|
|
||||||
<Tr cls="subtle mt-4" t={t.tos} />
|
<Tr cls="subtle mt-4" t={t.tos} />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if $debug || $test}
|
||||||
|
<span class="self-end subtle">{$subject}</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</ReviewPrivacyShield>
|
</ReviewPrivacyShield>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue