Last fixes to the reviews

This commit is contained in:
Pieter Vander Vennet 2020-12-11 15:27:52 +01:00
parent d80037e407
commit a53c4119e5
8 changed files with 59 additions and 23 deletions

View file

@ -135,7 +135,8 @@ export default class AllTranslationAssets {
affiliated_reviewer_warning: new Translation( {"en":"(Affiliated review)","nl":"(Review door betrokkene)"} ), affiliated_reviewer_warning: new Translation( {"en":"(Affiliated review)","nl":"(Review door betrokkene)"} ),
saving_review: new Translation( {"en":"Saving...","nl":"Opslaan..."} ), saving_review: new Translation( {"en":"Saving...","nl":"Opslaan..."} ),
saved: new Translation( {"en":"<span class='thanks'>Review saved. Thanks for sharing!</span>","nl":"<span class='thanks'>Bedankt om je beoordeling te delen!</span>"} ), saved: new Translation( {"en":"<span class='thanks'>Review saved. Thanks for sharing!</span>","nl":"<span class='thanks'>Bedankt om je beoordeling te delen!</span>"} ),
attribution: new Translation( {"en":"Reviews are powered by <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> and are available under <a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0</a>","nl":"De beoordelingen worden voorzien door <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> en zijn beschikbaar onder de<a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0-licentie</a> "} ), tos: new Translation( {"en":"If you create a review, you agree to <a href='https://mangrove.reviews/terms' target='_blank'>the TOS and privacy policy of Mangrove.reviews</a>","nl":"Als je je review publiceert, ga je akkoord met de <a href='https://mangrove.reviews/terms' target='_blank'>de gebruiksvoorwaarden en privacy policy van Mangrove.reviews</a>"} ),
attribution: new Translation( {"en":"Reviews are powered by <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> and are available under <a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0</a>.","nl":"De beoordelingen worden voorzien door <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> en zijn beschikbaar onder de<a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0-licentie</a>. "} ),
plz_login: new Translation( {"en":"Login to leave a review","nl":"Meld je aan om een beoordeling te geven"} ), plz_login: new Translation( {"en":"Login to leave a review","nl":"Meld je aan om een beoordeling te geven"} ),
}, },
}} }}

View file

@ -13,6 +13,7 @@ export class MangroveIdentity {
if (str === undefined || str === "") { if (str === undefined || str === "") {
return; return;
} }
console.log("JWK ", JSON.parse(str));
mangrove.jwkToKeypair(JSON.parse(str)).then(keypair => { mangrove.jwkToKeypair(JSON.parse(str)).then(keypair => {
self.keypair = keypair; self.keypair = keypair;
console.log("Identity loaded") console.log("Identity loaded")
@ -113,15 +114,24 @@ export default class MangroveReviews {
mangrove.getReviews({sub: this.GetSubjectUri()}).then( mangrove.getReviews({sub: this.GetSubjectUri()}).then(
(data) => { (data) => {
const reviews = []; const reviews = [];
const reviewsByUser = [];
for (const review of data.reviews) { for (const review of data.reviews) {
const r = review.payload; const r = review.payload;
reviews.push({ console.log("PublicKey is ",self._mangroveIdentity.keypair, "reviews is",review.signature);
const byUser = self._mangroveIdentity.keypair.publicKey === review.signature;
console.log("IS SAME: ", byUser);
const rev: Review = {
made_by_user: byUser,
date: new Date(r.iat * 1000), date: new Date(r.iat * 1000),
comment: r.opinion, comment: r.opinion,
author: r.metadata.nickname, author: r.metadata.nickname,
affiliated: r.metadata.is_affiliated, affiliated: r.metadata.is_affiliated,
rating: r.rating // percentage points rating: r.rating // percentage points
}) };
(rev.made_by_user ? reviewsByUser : reviews).push(rev);
} }
self._reviews.setData(reviews) self._reviews.setData(reviews)
} }
@ -141,19 +151,38 @@ export default class MangroveReviews {
rating: r.rating, rating: r.rating,
opinion: r.comment, opinion: r.comment,
metadata: { metadata: {
is_affiliated: r.affiliated,
nickname: r.author, nickname: r.author,
} }
}; };
if (r.affiliated) {
// @ts-ignore
payload.metadata.is_affiliated = true;
}
if (this._dryRun) { if (this._dryRun) {
console.log("DRYRUNNING mangrove reviews: ", payload); console.warn("DRYRUNNING mangrove reviews: ", payload);
} else { if (callback) {
mangrove.signAndSubmitReview(this._mangroveIdentity.keypair, payload).then(callback) if (callback) {
console.log("Calling callback")
callback();
} }
this._reviews.data.push(r); this._reviews.data.push(r);
this._reviews.ping(); this._reviews.ping();
}
} else {
mangrove.signAndSubmitReview(this._mangroveIdentity.keypair, payload).then(() => {
if (callback) {
console.log("Calling callback")
callback(); callback();
} }
this._reviews.data.push(r);
this._reviews.ping();
})
}
}
} }

View file

@ -3,5 +3,9 @@ export interface Review {
author: string, author: string,
date: Date, date: Date,
rating: number, rating: number,
affiliated: boolean affiliated: boolean,
/**
* True if the current logged in user is the creator of this comment
*/
made_by_user: boolean
} }

View file

@ -24,7 +24,7 @@ export default class State {
// The singleton of the global state // The singleton of the global state
public static state: State; public static state: State;
public static vNumber = "0.2.5-rc1"; public static vNumber = "0.2.5-rc2";
// The user journey states thresholds when a new feature gets unlocked // The user journey states thresholds when a new feature gets unlocked
public static userJourney = { public static userJourney = {

View file

@ -27,6 +27,7 @@ export default class ReviewForm extends InputElement<Review> {
this.userDetails = userDetails; this.userDetails = userDetails;
const t = Translations.t.reviews; const t = Translations.t.reviews;
this._value = new UIEventSource({ this._value = new UIEventSource({
made_by_user: false,
rating: undefined, rating: undefined,
comment: undefined, comment: undefined,
author: userDetails.data.name, author: userDetails.data.name,
@ -53,7 +54,7 @@ export default class ReviewForm extends InputElement<Review> {
.onClick(() => { .onClick(() => {
self._saveButton = Translations.t.reviews.saving_review; self._saveButton = Translations.t.reviews.saving_review;
onSave(this._value.data, () => { onSave(this._value.data, () => {
self._saveButton = Translations.t.reviews.saved; self._saveButton = Translations.t.reviews.saved.SetClass("thanks");
}); });
}) })
@ -97,7 +98,9 @@ export default class ReviewForm extends InputElement<Review> {
new Combine([ new Combine([
this._isAffiliated, this._isAffiliated,
this._saveButton this._saveButton
]).SetClass("review-form-bottom") ]).SetClass("review-form-bottom"),
"<br/>",
Translations.t.reviews.tos.SetClass("subtle")
]) ])
.SetClass("review-form") .SetClass("review-form")
.Render(); .Render();

View file

@ -168,7 +168,7 @@ export default class SpecialVisualizations {
State.state.mangroveIdentity, State.state.mangroveIdentity,
State.state.osmConnection._dryRun State.state.osmConnection._dryRun
); );
const form = new ReviewForm(r => mangrove.AddReview(r), State.state.osmConnection.userDetails); const form = new ReviewForm((r, whenDone) => mangrove.AddReview(r, whenDone), State.state.osmConnection.userDetails);
return new ReviewElement(mangrove.GetSubjectUri(), mangrove.GetReviews(), form); return new ReviewElement(mangrove.GetSubjectUri(), mangrove.GetReviews(), form);
} }
}, },

View file

@ -953,9 +953,13 @@
"en": "<span class='thanks'>Review saved. Thanks for sharing!</span>", "en": "<span class='thanks'>Review saved. Thanks for sharing!</span>",
"nl": "<span class='thanks'>Bedankt om je beoordeling te delen!</span>" "nl": "<span class='thanks'>Bedankt om je beoordeling te delen!</span>"
}, },
"tos": {
"en": "If you create a review, you agree to <a href='https://mangrove.reviews/terms' target='_blank'>the TOS and privacy policy of Mangrove.reviews</a>",
"nl": "Als je je review publiceert, ga je akkoord met de <a href='https://mangrove.reviews/terms' target='_blank'>de gebruiksvoorwaarden en privacy policy van Mangrove.reviews</a>"
},
"attribution": { "attribution": {
"en": "Reviews are powered by <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> and are available under <a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0</a>", "en": "Reviews are powered by <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> and are available under <a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0</a>.",
"nl": "De beoordelingen worden voorzien door <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> en zijn beschikbaar onder de<a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0-licentie</a> " "nl": "De beoordelingen worden voorzien door <a href='https://mangrove.reviews/' target='_blank'>Mangrove Reviews</a> en zijn beschikbaar onder de<a href='https://mangrove.reviews/terms#8-licensing-of-content' target='_blank'>CC-BY 4.0-licentie</a>. "
}, },
"plz_login": { "plz_login": {
"en": "Login to leave a review", "en": "Login to leave a review",

5
package-lock.json generated
View file

@ -6805,11 +6805,6 @@
} }
} }
}, },
"jose": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/jose/-/jose-3.3.1.tgz",
"integrity": "sha512-dMVfVKnyJyl2d9OBkwu/nvheGh9fbS1khhkJdvbGnINNe8IUfSJ/U+BXJOQvk65BCIJ58lp7xQKJTGQQ5dxrZA=="
},
"jquery": { "jquery": {
"version": "3.5.1", "version": "3.5.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",