From e11442e1009465e8bc3e8823e8d66fe44fb5f9c2 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 28 Mar 2024 02:23:13 +0100 Subject: [PATCH] Fix: fix #1844 --- langs/en.json | 3 ++ langs/layers/en.json | 2 +- src/Logic/Web/MangroveReviews.ts | 54 +++++++++++++++++++-------- src/UI/Reviews/ReviewsOverview.svelte | 54 +++++++++++++++++++-------- 4 files changed, 80 insertions(+), 33 deletions(-) diff --git a/langs/en.json b/langs/en.json index 20051074e..270b42ff3 100644 --- a/langs/en.json +++ b/langs/en.json @@ -672,6 +672,8 @@ "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", "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_opinion": "How was your experience?", "rate": "Rate {n} stars", @@ -683,6 +685,7 @@ "save": "Save review", "saved": "Review saved. Thanks for sharing!", "saving_review": "Saving…", + "see_all": "See all your reviews on mangrove.reviews", "title": "{count} reviews", "title_singular": "One review", "too_long": "At most {max} characters are allowed. Your review has {amount} characters.", diff --git a/langs/layers/en.json b/langs/layers/en.json index 57f41a22a..394c22cbf 100644 --- a/langs/layers/en.json +++ b/langs/layers/en.json @@ -11243,4 +11243,4 @@ "render": "wind turbine" } } -} +} \ No newline at end of file diff --git a/src/Logic/Web/MangroveReviews.ts b/src/Logic/Web/MangroveReviews.ts index 3fa410389..bc77549db 100644 --- a/src/Logic/Web/MangroveReviews.ts +++ b/src/Logic/Web/MangroveReviews.ts @@ -3,6 +3,7 @@ import { MangroveReviews, Review } from "mangrove-reviews-typescript" import { Utils } from "../../Utils" import { Feature, Position } from "geojson" import { GeoOperations } from "../GeoOperations" +import ScriptUtils from "../../../scripts/ScriptUtils" export class MangroveIdentity { private readonly keypair: Store @@ -70,31 +71,52 @@ export class MangroveIdentity { 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 })[]> = undefined /** * 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) { return this.allReviewsById } - this.allReviewsById = new UIEventSource([]) - this.key_id.map((pem) => { + this.allReviewsById = new UIEventSource(undefined) + this.key_id.map(async (pem) => { if (pem === undefined) { return [] } - MangroveReviews.getReviews({ - kid: pem, - }).then((allReviews) => { - this.allReviewsById.setData( - allReviews.reviews.map((r) => ({ - ...r, - ...r.payload, - })) - ) + const allReviews = await MangroveReviews.getReviews({ + kid: pem }) + this.allReviewsById.setData( + allReviews.reviews.map((r) => ({ + ...r, + ...r.payload + })) + ) }) return this.allReviewsById } @@ -243,7 +265,7 @@ export default class FeatureReviews { } const r: Review = { sub: this.subjectUri.data, - ...review, + ...review } const keypair: CryptoKeyPair = await this._identity.getKeypair() const jwt = await MangroveReviews.signReview(keypair, r) @@ -253,7 +275,7 @@ export default class FeatureReviews { ...r, kid, signature: jwt, - madeByLoggedInUser: new ImmutableStore(true), + madeByLoggedInUser: new ImmutableStore(true) } this._reviews.data.push(reviewWithKid) this._reviews.ping() @@ -301,7 +323,7 @@ export default class FeatureReviews { signature: reviewData.signature, madeByLoggedInUser: this._identity.getKeyId().map((user_key_id) => { return reviewData.kid === user_key_id - }), + }) }) hasNew = true } @@ -322,7 +344,7 @@ export default class FeatureReviews { // 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 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)}` if (name) { uri += "&q=" + (dontEncodeName ? name : encodeURIComponent(name)) diff --git a/src/UI/Reviews/ReviewsOverview.svelte b/src/UI/Reviews/ReviewsOverview.svelte index 124636d5f..d956724e1 100644 --- a/src/UI/Reviews/ReviewsOverview.svelte +++ b/src/UI/Reviews/ReviewsOverview.svelte @@ -6,12 +6,15 @@ import LoginButton from "../Base/LoginButton.svelte" import SingleReview from "./SingleReview.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 */ 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 @@ -22,23 +25,42 @@ - {#if $reviews?.length > 0} -
console.log("Got keypress", e)}> - {#each $reviews as review (review.sub)} - - {/each} -
+ {#if $reviews === undefined} + {:else} - + {#if $reviews?.length > 0} +
console.log("Got keypress", e)}> + {#each $reviews as review (review.sub)} + + {/each} +
+ {:else} + + {/if} + + {#if $allReviews?.length > $reviews?.length} + {#if $allReviews?.length - $reviews?.length === 1} + + {:else} + + {/if} + + + + {/if} + + + {/if} - - -