From fa9aca0685de5ea1ec16216836eac203d3188d96 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 12 Feb 2024 15:53:37 +0100 Subject: [PATCH] UX: add warning for too long reviews, see #1775 --- langs/en.json | 1 + src/Logic/Web/MangroveReviews.ts | 7 ++ src/UI/Reviews/ReviewForm.svelte | 119 ++++++++++++++++++------------- 3 files changed, 77 insertions(+), 50 deletions(-) diff --git a/langs/en.json b/langs/en.json index 613b798f1..b2a5760c3 100644 --- a/langs/en.json +++ b/langs/en.json @@ -676,6 +676,7 @@ "saving_review": "Saving…", "title": "{count} reviews", "title_singular": "One review", + "too_long": "At most {max} characters are allowed. Your review has {amount} characters.", "tos": "If you create a review, you agree to the TOS and privacy policy of Mangrove.reviews", "write_a_comment": "Leave a review…" }, diff --git a/src/Logic/Web/MangroveReviews.ts b/src/Logic/Web/MangroveReviews.ts index 85788ca49..3aa9582f6 100644 --- a/src/Logic/Web/MangroveReviews.ts +++ b/src/Logic/Web/MangroveReviews.ts @@ -52,6 +52,10 @@ export class MangroveIdentity { * Tracks all reviews of a given feature, allows to create a new review */ export default class FeatureReviews { + /** + * See https://gitlab.com/open-reviews/mangrove/-/blob/master/servers/reviewer/src/review.rs#L269 and https://github.com/pietervdvn/MapComplete/issues/1775 + */ + public static readonly REVIEW_OPINION_MAX_LENGTH = 1000 private static readonly _featureReviewsCache: Record = {} public readonly subjectUri: Store public readonly average: Store @@ -172,6 +176,9 @@ export default class FeatureReviews { * The given review is uploaded to mangrove.reviews and added to the list of known reviews */ public async createReview(review: Omit): Promise { + if(review.opinion.length > FeatureReviews .REVIEW_OPINION_MAX_LENGTH){ + throw "Opinion too long, should be at most "+FeatureReviews.REVIEW_OPINION_MAX_LENGTH+" characters long" + } const r: Review = { sub: this.subjectUri.data, ...review, diff --git a/src/UI/Reviews/ReviewForm.svelte b/src/UI/Reviews/ReviewForm.svelte index 7cd9242f5..d6f06e40a 100644 --- a/src/UI/Reviews/ReviewForm.svelte +++ b/src/UI/Reviews/ReviewForm.svelte @@ -1,60 +1,72 @@ {#if _state === "done"} @@ -95,6 +107,12 @@ class="mb-1 w-full" use:placeholder={t.reviewPlaceholder} /> + {#if $hasError === "too_long"} +
+ + +
+ {/if} @@ -108,7 +126,8 @@ -