flotilla/src/app/components/PeopleItem.svelte

73 lines
2.4 KiB
Svelte
Raw Normal View History

2024-10-01 21:55:33 +00:00
<script lang="ts">
2024-10-08 18:39:16 +00:00
import {onMount} from "svelte"
2025-05-05 17:11:02 +00:00
import {formatTimestampRelative} from "@welshman/lib"
2024-10-08 18:39:16 +00:00
import type {Filter} from "@welshman/util"
2025-06-05 19:25:55 +00:00
import {NOTE, GROUPS, MESSAGE, THREAD, COMMENT, getRelayTags, getListTags} from "@welshman/util"
2024-10-08 18:39:16 +00:00
import {deriveEvents} from "@welshman/store"
2025-04-09 22:32:18 +00:00
import {load} from "@welshman/net"
import {Router} from "@welshman/router"
2025-05-05 17:11:02 +00:00
import {repository, loadRelaySelections} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
2025-06-05 19:25:55 +00:00
import Button from "@lib/components/Button.svelte"
2024-10-01 21:55:33 +00:00
import Profile from "@app/components/Profile.svelte"
import ProfileInfo from "@app/components/ProfileInfo.svelte"
2025-06-05 19:25:55 +00:00
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import {membershipsByPubkey} from "@app/state"
import {pushModal} from "@app/modal"
2024-10-01 21:55:33 +00:00
2025-04-15 18:03:27 +00:00
type Props = {
pubkey: string
url?: string
}
const {pubkey, url}: Props = $props()
2025-01-17 23:01:05 +00:00
const filters: Filter[] = [{authors: [pubkey], limit: 1}]
2024-10-01 21:55:33 +00:00
const events = deriveEvents(repository, {filters})
2025-06-05 19:25:55 +00:00
const membership = $derived($membershipsByPubkey.get(pubkey))
const relays = $derived(getRelayTags(getListTags(membership)))
const openProfile = () => pushModal(ProfileDetail, {pubkey, url})
2024-10-01 21:55:33 +00:00
onMount(async () => {
// Make sure we have their relay selections before we load their posts
await loadRelaySelections(pubkey)
2025-06-05 19:25:55 +00:00
// Load groups and at least one note, regardless of time frame
2024-10-01 21:55:33 +00:00
load({
2025-06-05 19:25:55 +00:00
filters: [
{authors: [pubkey], kinds: [GROUPS]},
{authors: [pubkey], limit: 1, kinds: [NOTE, MESSAGE, THREAD, COMMENT]},
],
2025-04-09 22:32:18 +00:00
relays: Router.get().FromPubkeys([pubkey]).getUrls(),
2024-10-01 21:55:33 +00:00
})
})
</script>
2024-10-21 21:03:36 +00:00
<div class="card2 bg-alt col-2 shadow-xl">
<div class="flex justify-between">
2025-04-15 18:03:27 +00:00
<Profile {pubkey} {url} />
2025-06-05 19:25:55 +00:00
<Button onclick={openProfile} class="btn btn-primary hidden sm:flex">
<Icon icon="user-circle" />
2025-06-05 19:25:55 +00:00
View Profile
</Button>
</div>
2025-04-15 18:03:27 +00:00
<ProfileInfo {pubkey} {url} />
2025-06-05 19:25:55 +00:00
<div class="flex flex-wrap gap-2">
{#if $events.length > 0}
<div class="badge badge-neutral">
Last active {formatTimestampRelative($events[0].created_at)}
</div>
{/if}
{#if relays.length > 0}
<div class="badge badge-neutral">
{relays.length}
{relays.length === 1 ? "space" : "spaces"}
</div>
{/if}
</div>
<Button onclick={openProfile} class="btn btn-primary sm:hidden">
<Icon icon="user-circle" />
2025-06-05 19:25:55 +00:00
View Profile
</Button>
</div>