2024-10-31 19:24:40 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
2024-11-13 01:44:29 +00:00
|
|
|
import {sortBy, uniqBy} from "@welshman/lib"
|
2024-11-19 17:36:05 +00:00
|
|
|
import {feedFromFilter, makeIntersectionFeed, makeRelayFeed} from "@welshman/feeds"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {NOTE} from "@welshman/util"
|
2024-11-13 01:44:29 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {getReplyTags} from "@welshman/domain"
|
|
|
|
|
import {Feeds} from "@welshman/app"
|
2024-10-31 19:24:40 +00:00
|
|
|
import {createScroller} from "@lib/html"
|
2024-11-19 21:24:18 +00:00
|
|
|
import {fly} from "@lib/transition"
|
2024-10-31 19:24:40 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import NoteItem from "@app/components/NoteItem.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {app} from "@app/core"
|
2024-10-31 19:24:40 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
pubkey: string
|
2025-02-04 00:37:14 +00:00
|
|
|
events?: TrustedEvent[]
|
|
|
|
|
hideLoading?: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {url, pubkey, events = $bindable([]), hideLoading = false}: Props = $props()
|
2024-10-31 19:24:40 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const ctrl = $app.use(Feeds).makeFeedController({
|
2024-11-13 01:44:29 +00:00
|
|
|
useWindowing: true,
|
2024-11-19 17:36:05 +00:00
|
|
|
feed: makeIntersectionFeed(
|
|
|
|
|
makeRelayFeed(url),
|
|
|
|
|
feedFromFilter({kinds: [NOTE], authors: [pubkey]}),
|
|
|
|
|
),
|
2024-11-13 01:44:29 +00:00
|
|
|
onEvent: (event: TrustedEvent) => {
|
2025-01-17 23:01:05 +00:00
|
|
|
if (getReplyTags(event.tags).replies.length === 0) {
|
2024-11-13 01:44:29 +00:00
|
|
|
buffer.push(event)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2024-10-31 19:24:40 +00:00
|
|
|
|
2025-02-04 00:37:14 +00:00
|
|
|
let element: Element | undefined = $state()
|
2024-11-13 01:44:29 +00:00
|
|
|
let buffer: TrustedEvent[] = []
|
2024-10-31 19:24:40 +00:00
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
const scroller = createScroller({
|
2025-02-04 00:37:14 +00:00
|
|
|
element: element!,
|
2024-10-31 19:24:40 +00:00
|
|
|
delay: 300,
|
|
|
|
|
threshold: 3000,
|
2024-11-13 01:44:29 +00:00
|
|
|
onScroll: () => {
|
|
|
|
|
buffer = uniqBy(
|
|
|
|
|
e => e.id,
|
|
|
|
|
sortBy(e => -e.created_at, buffer),
|
|
|
|
|
)
|
2025-05-08 16:07:24 +00:00
|
|
|
|
|
|
|
|
events = uniqBy(e => e.id, [...events, ...buffer.splice(0, 5)])
|
2024-11-13 01:44:29 +00:00
|
|
|
|
|
|
|
|
if (buffer.length < 50) {
|
|
|
|
|
ctrl.load(50)
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-10-31 19:24:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return () => scroller.stop()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="flex flex-col gap-4" bind:this={element}>
|
2024-10-31 19:24:40 +00:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-11-13 01:44:29 +00:00
|
|
|
{#each events as event (event.id)}
|
2024-11-19 21:24:18 +00:00
|
|
|
<div in:fly>
|
|
|
|
|
<NoteItem {url} {event} />
|
|
|
|
|
</div>
|
2024-10-31 19:24:40 +00:00
|
|
|
{/each}
|
2024-12-11 22:10:20 +00:00
|
|
|
{#if !hideLoading}
|
2026-06-24 20:56:53 +00:00
|
|
|
<p class="justify-center items-center my-12 flex">
|
2024-12-11 22:10:20 +00:00
|
|
|
<Spinner loading />
|
|
|
|
|
</p>
|
|
|
|
|
{/if}
|
2024-10-31 19:24:40 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|