forked from MapComplete/MapComplete
Fix: fix #1844
This commit is contained in:
parent
5f967555eb
commit
e11442e100
4 changed files with 80 additions and 33 deletions
|
@ -672,6 +672,8 @@
|
||||||
"i_am_affiliated_explanation": "Check if you are an owner, creator, employee, …",
|
"i_am_affiliated_explanation": "Check if you are an owner, creator, employee, …",
|
||||||
"name_required": "A name is required in order to display and create reviews",
|
"name_required": "A name is required in order to display and create reviews",
|
||||||
"no_reviews_yet": "There are no reviews yet. Be the first to write one and help open data and the business!",
|
"no_reviews_yet": "There are no reviews yet. Be the first to write one and help open data and the business!",
|
||||||
|
"non_place_review": "One review is not about a place and is not shown here.",
|
||||||
|
"non_place_reviews": "{n} reviews are not about a place and are not shown here.",
|
||||||
"question": "How would you rate {title()}?",
|
"question": "How would you rate {title()}?",
|
||||||
"question_opinion": "How was your experience?",
|
"question_opinion": "How was your experience?",
|
||||||
"rate": "Rate {n} stars",
|
"rate": "Rate {n} stars",
|
||||||
|
@ -683,6 +685,7 @@
|
||||||
"save": "Save review",
|
"save": "Save review",
|
||||||
"saved": "Review saved. Thanks for sharing!",
|
"saved": "Review saved. Thanks for sharing!",
|
||||||
"saving_review": "Saving…",
|
"saving_review": "Saving…",
|
||||||
|
"see_all": "See all your reviews on mangrove.reviews",
|
||||||
"title": "{count} reviews",
|
"title": "{count} reviews",
|
||||||
"title_singular": "One review",
|
"title_singular": "One review",
|
||||||
"too_long": "At most {max} characters are allowed. Your review has {amount} characters.",
|
"too_long": "At most {max} characters are allowed. Your review has {amount} characters.",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { MangroveReviews, Review } from "mangrove-reviews-typescript"
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
import { Feature, Position } from "geojson"
|
import { Feature, Position } from "geojson"
|
||||||
import { GeoOperations } from "../GeoOperations"
|
import { GeoOperations } from "../GeoOperations"
|
||||||
|
import ScriptUtils from "../../../scripts/ScriptUtils"
|
||||||
|
|
||||||
export class MangroveIdentity {
|
export class MangroveIdentity {
|
||||||
private readonly keypair: Store<CryptoKeyPair>
|
private readonly keypair: Store<CryptoKeyPair>
|
||||||
|
@ -70,31 +71,52 @@ export class MangroveIdentity {
|
||||||
return this.key_id
|
return this.key_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private geoReviewsById: Store<(Review & { kid: string; signature: string })[]> =
|
||||||
|
undefined
|
||||||
|
|
||||||
|
public getGeoReviews(): Store<(Review & { kid: string, signature: string })[] | undefined> {
|
||||||
|
if (!this.geoReviewsById) {
|
||||||
|
const all = this.getAllReviews()
|
||||||
|
this.geoReviewsById = this.getAllReviews().mapD(reviews => reviews.filter(
|
||||||
|
review => {
|
||||||
|
try{
|
||||||
|
const subjectUrl = new URL(review.sub)
|
||||||
|
console.log(">>>", subjectUrl)
|
||||||
|
return subjectUrl.protocol === "geo:"
|
||||||
|
}catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return this.geoReviewsById
|
||||||
|
}
|
||||||
|
|
||||||
private allReviewsById: UIEventSource<(Review & { kid: string; signature: string })[]> =
|
private allReviewsById: UIEventSource<(Review & { kid: string; signature: string })[]> =
|
||||||
undefined
|
undefined
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all reviews that are made for the current identity.
|
* Gets all reviews that are made for the current identity.
|
||||||
|
* The returned store will contain `undefined` if still loading
|
||||||
*/
|
*/
|
||||||
public getAllReviews(): Store<(Review & { kid: string; signature: string })[]> {
|
public getAllReviews(): Store<(Review & { kid: string; signature: string })[] | undefined> {
|
||||||
if (this.allReviewsById !== undefined) {
|
if (this.allReviewsById !== undefined) {
|
||||||
return this.allReviewsById
|
return this.allReviewsById
|
||||||
}
|
}
|
||||||
this.allReviewsById = new UIEventSource([])
|
this.allReviewsById = new UIEventSource(undefined)
|
||||||
this.key_id.map((pem) => {
|
this.key_id.map(async (pem) => {
|
||||||
if (pem === undefined) {
|
if (pem === undefined) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
MangroveReviews.getReviews({
|
const allReviews = await MangroveReviews.getReviews({
|
||||||
kid: pem,
|
kid: pem
|
||||||
}).then((allReviews) => {
|
|
||||||
this.allReviewsById.setData(
|
|
||||||
allReviews.reviews.map((r) => ({
|
|
||||||
...r,
|
|
||||||
...r.payload,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
this.allReviewsById.setData(
|
||||||
|
allReviews.reviews.map((r) => ({
|
||||||
|
...r,
|
||||||
|
...r.payload
|
||||||
|
}))
|
||||||
|
)
|
||||||
})
|
})
|
||||||
return this.allReviewsById
|
return this.allReviewsById
|
||||||
}
|
}
|
||||||
|
@ -243,7 +265,7 @@ export default class FeatureReviews {
|
||||||
}
|
}
|
||||||
const r: Review = {
|
const r: Review = {
|
||||||
sub: this.subjectUri.data,
|
sub: this.subjectUri.data,
|
||||||
...review,
|
...review
|
||||||
}
|
}
|
||||||
const keypair: CryptoKeyPair = await this._identity.getKeypair()
|
const keypair: CryptoKeyPair = await this._identity.getKeypair()
|
||||||
const jwt = await MangroveReviews.signReview(keypair, r)
|
const jwt = await MangroveReviews.signReview(keypair, r)
|
||||||
|
@ -253,7 +275,7 @@ export default class FeatureReviews {
|
||||||
...r,
|
...r,
|
||||||
kid,
|
kid,
|
||||||
signature: jwt,
|
signature: jwt,
|
||||||
madeByLoggedInUser: new ImmutableStore(true),
|
madeByLoggedInUser: new ImmutableStore(true)
|
||||||
}
|
}
|
||||||
this._reviews.data.push(reviewWithKid)
|
this._reviews.data.push(reviewWithKid)
|
||||||
this._reviews.ping()
|
this._reviews.ping()
|
||||||
|
@ -301,7 +323,7 @@ export default class FeatureReviews {
|
||||||
signature: reviewData.signature,
|
signature: reviewData.signature,
|
||||||
madeByLoggedInUser: this._identity.getKeyId().map((user_key_id) => {
|
madeByLoggedInUser: this._identity.getKeyId().map((user_key_id) => {
|
||||||
return reviewData.kid === user_key_id
|
return reviewData.kid === user_key_id
|
||||||
}),
|
})
|
||||||
})
|
})
|
||||||
hasNew = true
|
hasNew = true
|
||||||
}
|
}
|
||||||
|
@ -322,7 +344,7 @@ export default class FeatureReviews {
|
||||||
// https://www.rfc-editor.org/rfc/rfc5870#section-3.4.2
|
// https://www.rfc-editor.org/rfc/rfc5870#section-3.4.2
|
||||||
// `u` stands for `uncertainty`, https://www.rfc-editor.org/rfc/rfc5870#section-3.4.3
|
// `u` stands for `uncertainty`, https://www.rfc-editor.org/rfc/rfc5870#section-3.4.3
|
||||||
const self = this
|
const self = this
|
||||||
return this._name.map(function (name) {
|
return this._name.map(function(name) {
|
||||||
let uri = `geo:${self._lat},${self._lon}?u=${Math.round(self._uncertainty)}`
|
let uri = `geo:${self._lat},${self._lon}?u=${Math.round(self._uncertainty)}`
|
||||||
if (name) {
|
if (name) {
|
||||||
uri += "&q=" + (dontEncodeName ? name : encodeURIComponent(name))
|
uri += "&q=" + (dontEncodeName ? name : encodeURIComponent(name))
|
||||||
|
|
|
@ -6,12 +6,15 @@
|
||||||
import LoginButton from "../Base/LoginButton.svelte"
|
import LoginButton from "../Base/LoginButton.svelte"
|
||||||
import SingleReview from "./SingleReview.svelte"
|
import SingleReview from "./SingleReview.svelte"
|
||||||
import Mangrove_logo from "../../assets/svg/Mangrove_logo.svelte"
|
import Mangrove_logo from "../../assets/svg/Mangrove_logo.svelte"
|
||||||
|
import Loading from "../Base/Loading.svelte"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A panel showing all the reviews by the logged-in user
|
* A panel showing all the reviews by the logged-in user
|
||||||
*/
|
*/
|
||||||
export let state: SpecialVisualizationState
|
export let state: SpecialVisualizationState
|
||||||
let reviews = state.userRelatedState.mangroveIdentity.getAllReviews()
|
let allReviews = state.userRelatedState.mangroveIdentity.getAllReviews()
|
||||||
|
let reviews = state.userRelatedState.mangroveIdentity.getGeoReviews()
|
||||||
|
let kid = state.userRelatedState.mangroveIdentity.getKeyId()
|
||||||
const t = Translations.t.reviews
|
const t = Translations.t.reviews
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -22,23 +25,42 @@
|
||||||
</LoginButton>
|
</LoginButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if $reviews?.length > 0}
|
{#if $reviews === undefined}
|
||||||
<div class="flex flex-col" on:keypress={(e) => console.log("Got keypress", e)}>
|
<Loading />
|
||||||
{#each $reviews as review (review.sub)}
|
|
||||||
<SingleReview {review} showSub={true} {state} />
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{:else}
|
{:else}
|
||||||
<Tr t={t.your_reviews_empty} />
|
{#if $reviews?.length > 0}
|
||||||
|
<div class="flex flex-col gap-y-1" on:keypress={(e) => console.log("Got keypress", e)}>
|
||||||
|
{#each $reviews as review (review.sub)}
|
||||||
|
<SingleReview {review} showSub={true} {state} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<Tr t={t.your_reviews_empty} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if $allReviews?.length > $reviews?.length}
|
||||||
|
{#if $allReviews?.length - $reviews?.length === 1}
|
||||||
|
<Tr t={t.non_place_review} />
|
||||||
|
{:else}
|
||||||
|
<Tr t={t.non_place_reviews.Subs({n:$allReviews?.length - $reviews?.length })} />
|
||||||
|
{/if}
|
||||||
|
<a target="_blank"
|
||||||
|
class="link-underline"
|
||||||
|
rel="noopener nofollow"
|
||||||
|
href={`https://mangrove.reviews/list?kid=${encodeURIComponent($kid)}`}
|
||||||
|
>
|
||||||
|
<Tr t={t.see_all} />
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
<a
|
||||||
|
class="link-underline"
|
||||||
|
href="https://github.com/pietervdvn/MapComplete/issues/1782"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<Tr t={t.reviews_bug} />
|
||||||
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
<a
|
|
||||||
class="link-underline"
|
|
||||||
href="https://github.com/pietervdvn/MapComplete/issues/1782"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<Tr t={t.reviews_bug} />
|
|
||||||
</a>
|
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<Mangrove_logo class="h-12 w-12 shrink-0 p-1" />
|
<Mangrove_logo class="h-12 w-12 shrink-0 p-1" />
|
||||||
<Tr cls="text-sm subtle" t={t.attribution} />
|
<Tr cls="text-sm subtle" t={t.attribution} />
|
||||||
|
|
Loading…
Reference in a new issue