forked from MapComplete/MapComplete
Use mangrove-reviews-typescript, rework reviews modules
This commit is contained in:
parent
93961e553f
commit
888d4e95a3
15 changed files with 768 additions and 375 deletions
108
test.ts
108
test.ts
|
@ -1,26 +1,90 @@
|
|||
import { LanguageElement } from "./UI/Popup/LanguageElement"
|
||||
import { ImmutableStore, UIEventSource } from "./Logic/UIEventSource"
|
||||
import MangroveReviewsOfFeature, { MangroveIdentity } from "./Logic/Web/MangroveReviews"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { OsmTags } from "./Models/OsmFeature"
|
||||
import { VariableUiElement } from "./UI/Base/VariableUIElement"
|
||||
import Locale from "./UI/i18n/Locale"
|
||||
import { OsmConnection } from "./Logic/Osm/OsmConnection"
|
||||
import List from "./UI/Base/List"
|
||||
import { UIEventSource } from "./Logic/UIEventSource"
|
||||
import UserRelatedState from "./Logic/State/UserRelatedState"
|
||||
|
||||
const tgs = new UIEventSource({
|
||||
name: "xyz",
|
||||
id: "node/1234",
|
||||
_country: "BE",
|
||||
const feature: Feature<Point, OsmTags> = {
|
||||
type: "Feature",
|
||||
id: "node/6739848322",
|
||||
properties: {
|
||||
"addr:city": "San Diego",
|
||||
"addr:housenumber": "2816",
|
||||
"addr:postcode": "92106",
|
||||
"addr:street": "Historic Decatur Road",
|
||||
"addr:unit": "116",
|
||||
amenity: "restaurant",
|
||||
cuisine: "burger",
|
||||
delivery: "yes",
|
||||
"diet:halal": "no",
|
||||
"diet:vegetarian": "yes",
|
||||
dog: "yes",
|
||||
image: "https://i.imgur.com/AQlGNHQ.jpg",
|
||||
internet_access: "wlan",
|
||||
"internet_access:fee": "no",
|
||||
"internet_access:ssid": "Public-stinebrewingCo",
|
||||
microbrewery: "yes",
|
||||
name: "Stone Brewing World Bistro & Gardens",
|
||||
opening_hours: "Mo-Fr, Su 11:30-21:00; Sa 11:30-22:00",
|
||||
organic: "no",
|
||||
"payment:cards": "yes",
|
||||
"payment:cash": "yes",
|
||||
"service:electricity": "ask",
|
||||
takeaway: "yes",
|
||||
website: "https://www.stonebrewing.com/visit/bistros/liberty-station",
|
||||
wheelchair: "designated",
|
||||
"_last_edit:contributor": "Drew Dowling",
|
||||
"_last_edit:timestamp": "2023-01-11T23:22:28Z",
|
||||
id: "node/6739848322",
|
||||
timestamp: "2023-01-11T23:22:28Z",
|
||||
user: "Drew Dowling",
|
||||
_backend: "https://www.openstreetmap.org",
|
||||
_lat: "32.7404614",
|
||||
_lon: "-117.211684",
|
||||
_layer: "food",
|
||||
_length: "0",
|
||||
"_length:km": "0.0",
|
||||
"_now:date": "2023-01-20",
|
||||
"_now:datetime": "2023-01-20 17:46:54",
|
||||
"_loaded:date": "2023-01-20",
|
||||
"_loaded:datetime": "2023-01-20 17:46:54",
|
||||
"_geometry:type": "Point",
|
||||
_surface: "0",
|
||||
"_surface:ha": "0",
|
||||
_country: "us",
|
||||
},
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [0, 0],
|
||||
},
|
||||
}
|
||||
const state = new UserRelatedState(undefined)
|
||||
|
||||
state.allElements.addOrGetElement(feature)
|
||||
|
||||
const reviews = MangroveReviewsOfFeature.construct(feature, state)
|
||||
|
||||
reviews.reviews.addCallbackAndRun((r) => {
|
||||
console.log("Reviews are:", r)
|
||||
})
|
||||
Locale.language.setData("nl")
|
||||
console.log(tgs)
|
||||
console.log("Locale", Locale.language)
|
||||
const conn = new OsmConnection({})
|
||||
new LanguageElement()
|
||||
.constr(<any>{ osmConnection: conn, featureSwitchIsTesting: new ImmutableStore(true) }, tgs, [
|
||||
"language",
|
||||
"What languages are spoken here?",
|
||||
"{language()} is spoken here",
|
||||
"{language()} is the only language spoken here",
|
||||
"The following languages are spoken here: {list()}",
|
||||
])
|
||||
.AttachTo("maindiv")
|
||||
window.setTimeout(async () => {
|
||||
await reviews.createReview({
|
||||
opinion: "Cool bar",
|
||||
rating: 90,
|
||||
metadata: {
|
||||
nickname: "Pietervdvn",
|
||||
},
|
||||
})
|
||||
console.log("Submitted review")
|
||||
}, 1000)
|
||||
|
||||
new VariableUiElement(tgs.map(JSON.stringify)).AttachTo("extradiv")
|
||||
new VariableUiElement(
|
||||
reviews.reviews.map(
|
||||
(reviews) =>
|
||||
new List(
|
||||
reviews.map((r) => r.rating + "% " + r.opinion + " (" + r.metadata.nickname + ")")
|
||||
)
|
||||
)
|
||||
).AttachTo("maindiv")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue