flotilla/src/app/components/WotScore.svelte

52 lines
1.3 KiB
Svelte
Raw Normal View History

2024-10-01 21:55:33 +00:00
<style>
.wot-background {
fill: transparent;
stroke: var(--content);
2024-10-01 21:55:33 +00:00
opacity: 30%;
}
.wot-highlight {
fill: transparent;
stroke-width: 1.5;
stroke-dasharray: 100 100;
transform-origin: center;
}
</style>
<script lang="ts">
2024-10-08 18:39:16 +00:00
import {clamp} from "@welshman/lib"
2026-07-28 16:16:26 +00:00
import {followLists, user, wot} from "@app/core"
2024-10-01 21:55:33 +00:00
2025-02-04 00:37:14 +00:00
interface Props {
2025-06-05 19:25:55 +00:00
pubkey: string
2025-02-04 00:37:14 +00:00
}
2025-06-05 19:25:55 +00:00
const {pubkey: target}: Props = $props()
2024-10-01 21:55:33 +00:00
2025-06-05 19:25:55 +00:00
const max = 100
2024-10-01 21:55:33 +00:00
const radius = 6
const center = radius + 1
2026-07-28 16:16:26 +00:00
const score = $derived($wot.wotScore($user.pubkey, target).$)
const follows = $derived($followLists.one($user.pubkey))
const active = $derived(($follows?.pubkeys() ?? []).includes(target))
2025-06-05 19:25:55 +00:00
const normalizedScore = $derived(clamp([0, max], $score) / max)
const dashOffset = $derived(100 - 44 * normalizedScore)
const style = $derived(`transform: rotate(${135 - normalizedScore * 180}deg)`)
const stroke = $derived(active ? "var(--primary)" : "var(--content)")
2024-10-01 21:55:33 +00:00
</script>
<div class="relative h-[14px] w-[14px]">
<svg height="14" width="14" class="absolute">
<circle class="wot-background" cx={center} cy={center} r={radius} />
<circle
cx={center}
cy={center}
r={radius}
class="wot-highlight"
stroke-dashoffset={dashOffset}
{style}
{stroke} />
</svg>
</div>