2023-09-28 04:02:42 +02:00
|
|
|
<script lang="ts">
|
2023-09-28 23:50:27 +02:00
|
|
|
import { Review } from "mangrove-reviews-typescript"
|
2024-02-15 03:11:10 +01:00
|
|
|
import { ImmutableStore, Store } from "../../Logic/UIEventSource"
|
2023-09-28 23:50:27 +02:00
|
|
|
import StarsBar from "./StarsBar.svelte"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
2023-12-24 05:01:10 +01:00
|
|
|
import { ariaLabel } from "../../Utils/ariaLabel"
|
2024-02-15 03:11:10 +01:00
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
2023-09-28 04:02:42 +02:00
|
|
|
|
2024-02-15 03:11:10 +01:00
|
|
|
export let state: SpecialVisualizationState = undefined
|
2024-02-20 13:33:38 +01:00
|
|
|
export let review: Review & {
|
|
|
|
kid: string
|
|
|
|
signature: string
|
|
|
|
madeByLoggedInUser?: Store<boolean>
|
|
|
|
}
|
2023-09-28 23:50:27 +02:00
|
|
|
let name = review.metadata.nickname
|
2023-12-24 05:01:10 +01:00
|
|
|
name ??= ((review.metadata.given_name ?? "") + " " + (review.metadata.family_name ?? "")).trim()
|
2023-09-28 23:50:27 +02:00
|
|
|
let d = new Date()
|
|
|
|
d.setTime(review.iat * 1000)
|
|
|
|
let date = d.toDateString()
|
2024-02-15 03:11:10 +01:00
|
|
|
let byLoggedInUser = review.madeByLoggedInUser ?? ImmutableStore.FALSE
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-02-15 03:11:10 +01:00
|
|
|
export let showSub = false
|
|
|
|
let subUrl = new URL(review.sub)
|
2024-02-20 13:33:38 +01:00
|
|
|
let [lat, lon] = subUrl.pathname.split(",").map((l) => Number(l))
|
2024-02-15 03:11:10 +01:00
|
|
|
let sub = subUrl.searchParams.get("q")
|
2024-02-20 13:33:38 +01:00
|
|
|
|
|
|
|
function selectFeature() {
|
|
|
|
console.log("Selecting and zooming to", { lon, lat })
|
|
|
|
state?.mapProperties?.location?.setData({ lon, lat })
|
|
|
|
state?.mapProperties?.zoom?.setData(Math.max(16, state?.mapProperties?.zoom?.data))
|
|
|
|
|
|
|
|
state?.guistate?.closeAll()
|
2024-02-15 03:11:10 +01:00
|
|
|
}
|
2023-09-28 04:02:42 +02:00
|
|
|
</script>
|
|
|
|
|
2024-02-20 13:33:38 +01:00
|
|
|
<div
|
|
|
|
class={"low-interaction flex flex-col rounded-lg p-1 px-2" +
|
|
|
|
($byLoggedInUser ? "border-interactive" : "")}
|
|
|
|
>
|
2024-02-15 03:11:10 +01:00
|
|
|
{#if showSub}
|
|
|
|
<button class="link" on:click={() => selectFeature()}>
|
2024-02-20 13:33:38 +01:00
|
|
|
<h3>{sub}</h3>
|
2024-02-15 03:11:10 +01:00
|
|
|
</button>
|
|
|
|
{/if}
|
2024-02-20 13:33:38 +01:00
|
|
|
<div class="flex w-full items-center justify-between">
|
2023-12-30 15:24:30 +01:00
|
|
|
<div
|
|
|
|
tabindex="0"
|
|
|
|
use:ariaLabel={Translations.t.reviews.rated.Subs({
|
|
|
|
n: "" + Math.round(review.rating / 10) / 2,
|
|
|
|
})}
|
|
|
|
>
|
2023-12-24 05:01:10 +01:00
|
|
|
<StarsBar readonly={true} score={review.rating} />
|
|
|
|
</div>
|
2023-09-28 04:02:42 +02:00
|
|
|
<div class="flex flex-wrap space-x-2">
|
2023-12-30 15:24:30 +01:00
|
|
|
<a
|
|
|
|
href={`https://mangrove.reviews/list?kid=${encodeURIComponent(review.kid)}`}
|
|
|
|
rel="noopener"
|
|
|
|
target="_blank"
|
|
|
|
>
|
2023-12-24 05:01:10 +01:00
|
|
|
{#if !name}
|
|
|
|
<i>Anonymous</i>
|
|
|
|
{:else}
|
|
|
|
<span class="font-bold">
|
2023-12-30 15:24:30 +01:00
|
|
|
{name}
|
2023-12-24 05:01:10 +01:00
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</a>
|
2023-09-28 23:50:27 +02:00
|
|
|
<span class="subtle">
|
|
|
|
{date}
|
|
|
|
</span>
|
2023-09-28 04:02:42 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{#if review.opinion}
|
2023-12-24 05:01:10 +01:00
|
|
|
<div class="link-no-underline">
|
2023-12-30 15:24:30 +01:00
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener nofollow"
|
|
|
|
href={`https://mangrove.reviews/list?signature=${encodeURIComponent(review.signature)}`}
|
|
|
|
>
|
|
|
|
{review.opinion}
|
|
|
|
</a>
|
2023-12-24 05:01:10 +01:00
|
|
|
</div>
|
2023-09-28 04:02:42 +02:00
|
|
|
{/if}
|
|
|
|
{#if review.metadata.is_affiliated}
|
|
|
|
<Tr t={Translations.t.reviews.affiliated_reviewer_warning} />
|
|
|
|
{/if}
|
|
|
|
</div>
|