forked from MapComplete/MapComplete
Feature(reviews): support deleting and editing reviews, fix #2129
This commit is contained in:
parent
3ee9ee9d88
commit
06ff00f7f7
8 changed files with 165 additions and 29 deletions
|
|
@ -150,7 +150,7 @@ export default class FeatureReviews {
|
|||
private readonly _reviews: UIEventSource<
|
||||
(Review & { kid: string; signature: string; madeByLoggedInUser: Store<boolean> })[]
|
||||
> = new UIEventSource([])
|
||||
public readonly reviews: Store<(Review & { madeByLoggedInUser: Store<boolean> })[]> =
|
||||
public readonly reviews: Store<(Review & { signature: string, madeByLoggedInUser: Store<boolean> })[]> =
|
||||
this._reviews
|
||||
private readonly _lat: number
|
||||
private readonly _lon: number
|
||||
|
|
@ -361,9 +361,10 @@ export default class FeatureReviews {
|
|||
const keypair: CryptoKeyPair = await this._identity.getKeypair()
|
||||
const jwt = await MangroveReviews.signReview(keypair, r)
|
||||
const kid = await MangroveReviews.publicToPem(keypair.publicKey)
|
||||
|
||||
if (!this._testmode.data) {
|
||||
try {
|
||||
await MangroveReviews.submitReview(jwt)
|
||||
await MangroveReviews.signAndSubmitReview(keypair, r)
|
||||
} catch (e) {
|
||||
await this._reportError(
|
||||
e,
|
||||
|
|
@ -375,10 +376,11 @@ export default class FeatureReviews {
|
|||
console.log("Testmode enabled - not uploading review")
|
||||
await Utils.waitFor(1000)
|
||||
}
|
||||
console.log("JWT IS", jwt)
|
||||
const reviewWithKid = {
|
||||
...r,
|
||||
kid,
|
||||
signature: jwt,
|
||||
signature: "",
|
||||
madeByLoggedInUser: new ImmutableStore(true),
|
||||
}
|
||||
this._reviews.data.push(reviewWithKid)
|
||||
|
|
@ -448,6 +450,13 @@ export default class FeatureReviews {
|
|||
}
|
||||
}
|
||||
|
||||
public async deleteReview(review: Review & {signature: string}){
|
||||
await MangroveReviews.deleteReview(await this._identity.getKeypair(), review)
|
||||
this._reviews.set(
|
||||
this._reviews.data.filter(r => r !== review)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an URI which represents the item in a mangrove-compatible way
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue