forked from MapComplete/MapComplete
Feature(reviews): add loading screen
This commit is contained in:
parent
feb0d47aec
commit
4c0c8ae9ea
2 changed files with 21 additions and 13 deletions
|
@ -149,7 +149,7 @@ export default class FeatureReviews {
|
||||||
public readonly average: Store<number | null>
|
public readonly average: Store<number | null>
|
||||||
private readonly _reviews: UIEventSource<
|
private readonly _reviews: UIEventSource<
|
||||||
(Review & { kid: string; signature: string; madeByLoggedInUser: Store<boolean> })[]
|
(Review & { kid: string; signature: string; madeByLoggedInUser: Store<boolean> })[]
|
||||||
> = new UIEventSource([])
|
> = new UIEventSource(undefined)
|
||||||
public readonly reviews: Store<(Review & { signature: string, madeByLoggedInUser: Store<boolean> })[]> =
|
public readonly reviews: Store<(Review & { signature: string, madeByLoggedInUser: Store<boolean> })[]> =
|
||||||
this._reviews
|
this._reviews
|
||||||
private readonly _lat: number
|
private readonly _lat: number
|
||||||
|
@ -159,11 +159,6 @@ export default class FeatureReviews {
|
||||||
private readonly _identity: MangroveIdentity
|
private readonly _identity: MangroveIdentity
|
||||||
private readonly _testmode: Store<boolean>
|
private readonly _testmode: Store<boolean>
|
||||||
public readonly loadingAllowed: UIEventSource<boolean | null>
|
public readonly loadingAllowed: UIEventSource<boolean | null>
|
||||||
private readonly _options: Readonly<{
|
|
||||||
nameKey?: "name" | string
|
|
||||||
fallbackName?: string
|
|
||||||
uncertaintyRadius?: number
|
|
||||||
}>
|
|
||||||
private readonly _reportError: (msg: string, extra: string) => Promise<void>
|
private readonly _reportError: (msg: string, extra: string) => Promise<void>
|
||||||
|
|
||||||
private constructor(
|
private constructor(
|
||||||
|
@ -186,7 +181,6 @@ export default class FeatureReviews {
|
||||||
this._identity = mangroveIdentity
|
this._identity = mangroveIdentity
|
||||||
this._testmode = testmode ?? new ImmutableStore(false)
|
this._testmode = testmode ?? new ImmutableStore(false)
|
||||||
const nameKey = options?.nameKey ?? "name"
|
const nameKey = options?.nameKey ?? "name"
|
||||||
this._options = options
|
|
||||||
if (options.uncertaintyRadius) {
|
if (options.uncertaintyRadius) {
|
||||||
this._uncertainty = options.uncertaintyRadius
|
this._uncertainty = options.uncertaintyRadius
|
||||||
} else if (feature.geometry.type === "Point") {
|
} else if (feature.geometry.type === "Point") {
|
||||||
|
@ -383,11 +377,18 @@ export default class FeatureReviews {
|
||||||
signature: "",
|
signature: "",
|
||||||
madeByLoggedInUser: new ImmutableStore(true),
|
madeByLoggedInUser: new ImmutableStore(true),
|
||||||
}
|
}
|
||||||
|
this.initReviews()
|
||||||
this._reviews.data.push(reviewWithKid)
|
this._reviews.data.push(reviewWithKid)
|
||||||
this._reviews.ping()
|
this._reviews.ping()
|
||||||
this._identity.addReview(reviewWithKid)
|
this._identity.addReview(reviewWithKid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initReviews(){
|
||||||
|
if(this._reviews.data === undefined){
|
||||||
|
this._reviews.set([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds given reviews to the 'reviews'-UI-eventsource, if they match close enough.
|
* Adds given reviews to the 'reviews'-UI-eventsource, if they match close enough.
|
||||||
* We assume only geo-reviews are passed in (as they should be queried using the 'geo'-part)
|
* We assume only geo-reviews are passed in (as they should be queried using the 'geo'-part)
|
||||||
|
@ -398,9 +399,11 @@ export default class FeatureReviews {
|
||||||
reviews: { payload: Review; kid: string; signature: string }[],
|
reviews: { payload: Review; kid: string; signature: string }[],
|
||||||
expectedName: string
|
expectedName: string
|
||||||
) {
|
) {
|
||||||
const alreadyKnown = new Set(this._reviews.data.map((r) => r.rating + " " + r.opinion))
|
const alreadyKnown = new Set(this._reviews.data?.map((r) => r.rating + " " + r.opinion))
|
||||||
|
|
||||||
let hasNew = false
|
let hasNew = false
|
||||||
|
this.initReviews()
|
||||||
|
|
||||||
for (const reviewData of reviews) {
|
for (const reviewData of reviews) {
|
||||||
const review = reviewData.payload
|
const review = reviewData.payload
|
||||||
|
|
||||||
|
@ -457,7 +460,7 @@ export default class FeatureReviews {
|
||||||
|
|
||||||
public removeReviewLocally(review: Review){
|
public removeReviewLocally(review: Review){
|
||||||
this._reviews.set(
|
this._reviews.set(
|
||||||
this._reviews.data.filter(r => r !== review)
|
this._reviews.data?.filter(r => r !== review)
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||||
import type { Feature } from "geojson"
|
import type { Feature } from "geojson"
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||||
|
import Loading from "../Base/Loading.svelte"
|
||||||
/**
|
/**
|
||||||
* An element showing all reviews
|
* An element showing all reviews
|
||||||
*/
|
*/
|
||||||
|
@ -33,22 +34,26 @@
|
||||||
|
|
||||||
<ReviewPrivacyShield {reviews} guistate={state.guistate}>
|
<ReviewPrivacyShield {reviews} guistate={state.guistate}>
|
||||||
<div class="border-2 border-dashed border-gray-300 p-2 flex flex-col gap-y-2">
|
<div class="border-2 border-dashed border-gray-300 p-2 flex flex-col gap-y-2">
|
||||||
{#if $allReviews.length > 1}
|
{#if $allReviews?.length > 1}
|
||||||
<StarsBar score={$average} />
|
<StarsBar score={$average} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if $allReviews.length > 0}
|
{#if !$allReviews}
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<Loading/>
|
||||||
|
</div>
|
||||||
|
{:else if $allReviews.length > 0}
|
||||||
{#each $allReviews as review}
|
{#each $allReviews as review}
|
||||||
<SingleReview {review} {state} {tags} {feature} {layer} {reviews}/>
|
<SingleReview {review} {state} {tags} {feature} {layer} {reviews}/>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
<div class="subtle m-2 italic">
|
<div class="subtle m-2 italic flex justify-center">
|
||||||
<Tr t={Translations.t.reviews.no_reviews_yet} />
|
<Tr t={Translations.t.reviews.no_reviews_yet} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<a
|
<a
|
||||||
href={"https://mangrove.reviews" +
|
href={"https://mangrove.reviews" +
|
||||||
($allReviews.length == 0 ? "" : "/search?sub=" + encodeURIComponent($subject))}
|
($allReviews?.length > 0 ?"/search?sub=" + encodeURIComponent($subject):"")}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="subtle text-sm"
|
class="subtle text-sm"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue