flotilla/src/app/components/ProfileBadges.svelte

45 lines
1.3 KiB
Svelte
Raw Normal View History

2025-06-05 20:01:36 +00:00
<script lang="ts">
import {onMount} from "svelte"
import {formatTimestampRelative} from "@welshman/lib"
import {NOTE, COMMENT, MESSAGE} from "@welshman/util"
2025-06-05 20:01:36 +00:00
import Button from "@lib/components/Button.svelte"
import ProfileSpaces from "@app/components/ProfileSpaces.svelte"
import {network, roomLists} from "@app/core"
import {deriveLatestEvent} from "@app/repository"
2026-06-08 21:14:40 +00:00
import {goToEvent} from "@app/routes"
import {pushModal} from "@app/modal"
2025-06-05 20:01:36 +00:00
type Props = {
pubkey: string
url?: string
}
const {pubkey, url}: Props = $props()
2026-07-28 16:16:26 +00:00
const latest = deriveLatestEvent(pubkey)
2026-07-28 16:16:26 +00:00
const spaceUrls = $roomLists.urls(pubkey).$
2025-06-05 20:01:36 +00:00
const viewEvent = () => goToEvent($latest!)
2025-06-05 20:37:50 +00:00
const openSpaces = () => pushModal(ProfileSpaces, {pubkey, url}, {label: "Profile spaces"})
2025-06-05 20:01:36 +00:00
onMount(() => {
$network.loadUsingOutbox(pubkey, {limit: 1, kinds: [NOTE, COMMENT, MESSAGE]})
2025-06-05 20:01:36 +00:00
})
</script>
<div class="flex flex-wrap gap-2">
{#if $latest}
2025-06-05 20:37:50 +00:00
<Button onclick={viewEvent} class="badge badge-neutral">
Last active {formatTimestampRelative($latest.created_at)}
2025-06-05 20:37:50 +00:00
</Button>
2025-06-05 20:01:36 +00:00
{/if}
2026-07-28 16:16:26 +00:00
{#if $spaceUrls.length > 0}
2025-06-05 20:01:36 +00:00
<Button onclick={openSpaces} class="badge badge-neutral">
2026-07-28 16:16:26 +00:00
{$spaceUrls.length}
{$spaceUrls.length === 1 ? "space" : "spaces"}
2025-06-05 20:01:36 +00:00
</Button>
{/if}
</div>