2026-06-18 10:52:04 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
2026-06-29 22:48:43 +00:00
|
|
|
import {derived, writable} from "svelte/store"
|
|
|
|
|
import type {Writable} from "svelte/store"
|
2026-06-29 23:28:11 +00:00
|
|
|
import {sortBy, uniqBy, now} from "@welshman/lib"
|
2026-06-18 10:52:04 +00:00
|
|
|
import {NOTE, getReplyTags, getListTags, getEventTagValues} from "@welshman/util"
|
|
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-06-29 22:48:43 +00:00
|
|
|
import {derivePinList} from "@welshman/app"
|
|
|
|
|
import {Router} from "@welshman/router"
|
|
|
|
|
import {load} from "@welshman/net"
|
2026-06-18 10:52:04 +00:00
|
|
|
import {fly} from "@lib/transition"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import NoteItem from "@app/components/NoteItem.svelte"
|
2026-06-29 22:48:43 +00:00
|
|
|
import {makeFeed} from "@app/feeds"
|
2026-06-18 10:52:04 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
pubkey: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {pubkey}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const pinList = derivePinList(pubkey)
|
2026-06-29 22:48:43 +00:00
|
|
|
const pinnedIds = derived(pinList, $pinList => getEventTagValues(getListTags($pinList)))
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
if ($pinnedIds.length > 0) {
|
|
|
|
|
const controller = new AbortController()
|
|
|
|
|
|
|
|
|
|
load({
|
|
|
|
|
relays: Router.get().FromPubkeys([pubkey]).getUrls(),
|
|
|
|
|
filters: [{ids: $pinnedIds}],
|
|
|
|
|
signal: controller.signal,
|
2026-06-29 23:28:11 +00:00
|
|
|
onEvent: e => events.update($events => uniqBy(e => e.id, $events.concat(e))),
|
2026-06-29 22:48:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return () => controller.abort()
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-06-18 10:52:04 +00:00
|
|
|
|
|
|
|
|
let element: HTMLElement | undefined = $state()
|
|
|
|
|
let exhausted = $state(false)
|
2026-06-29 22:48:43 +00:00
|
|
|
let events: Writable<TrustedEvent[]> = $state(writable([]))
|
2026-06-18 10:52:04 +00:00
|
|
|
|
2026-06-29 22:48:43 +00:00
|
|
|
const feedEvents = $derived(
|
|
|
|
|
sortBy(
|
|
|
|
|
e => ($pinnedIds.includes(e.id) ? -(now() + e.created_at) : -e.created_at),
|
|
|
|
|
$events.filter(e => getReplyTags(e.tags).replies.length === 0),
|
|
|
|
|
),
|
|
|
|
|
)
|
2026-06-18 10:52:04 +00:00
|
|
|
|
|
|
|
|
onMount(() => {
|
2026-06-29 22:48:43 +00:00
|
|
|
const feed = makeFeed({
|
2026-06-29 23:28:11 +00:00
|
|
|
relays: Router.get().FromPubkeys([pubkey]).getUrls(),
|
2026-06-18 10:52:04 +00:00
|
|
|
element: element!,
|
2026-06-29 22:48:43 +00:00
|
|
|
filters: [{kinds: [NOTE], authors: [pubkey]}],
|
|
|
|
|
onBackwardExhausted: () => {
|
|
|
|
|
exhausted = true
|
2026-06-18 10:52:04 +00:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-29 22:48:43 +00:00
|
|
|
events = feed.events
|
|
|
|
|
|
|
|
|
|
return () => feed.cleanup()
|
2026-06-18 10:52:04 +00:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="flex flex-col gap-4" bind:this={element}>
|
2026-06-29 22:48:43 +00:00
|
|
|
{#each feedEvents as event (event.id)}
|
2026-06-18 10:52:04 +00:00
|
|
|
<div in:fly>
|
|
|
|
|
<NoteItem {event} />
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
{#if exhausted}
|
|
|
|
|
<p class="py-12 text-center text-sm opacity-75">No notes found for this profile.</p>
|
|
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
{#if !exhausted}
|
2026-06-29 23:28:11 +00:00
|
|
|
<p class="my-12 flex items-center justify-center gap-2">
|
2026-06-18 10:52:04 +00:00
|
|
|
<Spinner loading />
|
2026-06-29 23:28:11 +00:00
|
|
|
Loading notes...
|
2026-06-18 10:52:04 +00:00
|
|
|
</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|