flotilla/src/app/components/ProfileBadges.svelte

59 lines
2 KiB
Svelte
Raw Normal View History

2025-06-05 20:01:36 +00:00
<script lang="ts">
import {onMount} from "svelte"
import {load} from "@welshman/net"
import {Router} from "@welshman/router"
import type {Filter} from "@welshman/util"
2026-02-09 21:21:38 +00:00
import {deriveEventsDesc, deriveEventsById} from "@welshman/store"
2025-06-05 20:01:36 +00:00
import {formatTimestampRelative} from "@welshman/lib"
import {NOTE, ROOMS, COMMENT} from "@welshman/util"
2025-11-20 23:12:16 +00:00
import {repository, loadRelayList} from "@welshman/app"
2025-06-05 20:01:36 +00:00
import Button from "@lib/components/Button.svelte"
import ProfileSpaces from "@app/components/ProfileSpaces.svelte"
2025-11-20 23:54:06 +00:00
import {deriveGroupList, getSpaceUrlsFromGroupList, MESSAGE_KINDS} from "@app/core/state"
import {goToEvent} from "@app/util/routes"
import {pushModal} from "@app/util/modal"
2025-06-05 20:01:36 +00:00
type Props = {
pubkey: string
url?: string
}
const {pubkey, url}: Props = $props()
const filters: Filter[] = [{authors: [pubkey], limit: 1}]
2026-02-09 21:21:38 +00:00
const events = deriveEventsDesc(deriveEventsById({repository, filters}))
2025-11-20 23:12:16 +00:00
const groupList = deriveGroupList(pubkey)
const spaceUrls = $derived(getSpaceUrlsFromGroupList($groupList))
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 () => {
// Make sure we have their relay selections before we load their posts
2025-11-20 23:12:16 +00:00
await loadRelayList(pubkey)
2025-06-05 20:01:36 +00:00
// Load groups and at least one note, regardless of time frame
load({
filters: [
2025-06-16 17:12:24 +00:00
{authors: [pubkey], kinds: [ROOMS]},
2025-10-06 18:23:19 +00:00
{authors: [pubkey], limit: 1, kinds: [NOTE, COMMENT, ...MESSAGE_KINDS]},
2025-06-05 20:01:36 +00:00
],
relays: Router.get().FromPubkeys([pubkey]).getUrls(),
})
})
</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}
{#if spaceUrls.length > 0}
2025-06-05 20:01:36 +00:00
<Button onclick={openSpaces} class="badge badge-neutral">
{spaceUrls.length}
{spaceUrls.length === 1 ? "space" : "spaces"}
2025-06-05 20:01:36 +00:00
</Button>
{/if}
</div>