flotilla/src/app/components/ProfileBadges.svelte

53 lines
1.5 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"
2026-07-28 16:16:26 +00:00
import {NOTE, ROOMS, COMMENT, MESSAGE, outbox} 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"
2026-07-28 16:16:26 +00:00
import {network, relayLists, roomLists, router} from "@app/core"
import {deriveEvents} 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 events = deriveEvents([{authors: [pubkey], limit: 1}])
const spaceUrls = $roomLists.urls(pubkey).$
2025-06-05 20:01:36 +00:00
2025-06-05 20:37:50 +00:00
const viewEvent = () => goToEvent($events[0]!)
2025-06-05 20:01:36 +00:00
const openSpaces = () => pushModal(ProfileSpaces, {pubkey, url})
onMount(async () => {
2026-07-28 16:16:26 +00:00
await $relayLists.load(pubkey)
2025-06-05 20:01:36 +00:00
2026-07-28 16:16:26 +00:00
$network.load({
2025-06-05 20:01:36 +00:00
filters: [
2025-06-16 17:12:24 +00:00
{authors: [pubkey], kinds: [ROOMS]},
{authors: [pubkey], limit: 1, kinds: [NOTE, COMMENT, MESSAGE]},
2025-06-05 20:01:36 +00:00
],
2026-07-28 16:16:26 +00:00
relays: await $router.resolver.relays([outbox(pubkey)]),
2025-06-05 20:01:36 +00:00
})
})
</script>
<div class="flex flex-wrap gap-2">
{#if $events.length > 0}
2025-06-05 20:37:50 +00:00
<Button onclick={viewEvent} class="badge badge-neutral">
2025-06-05 20:01:36 +00:00
Last active {formatTimestampRelative($events[0].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>