flotilla/src/app/components/ChannelThread.svelte

44 lines
1.4 KiB
Svelte
Raw Normal View History

2024-10-01 18:47:21 +00:00
<script lang="ts">
2024-10-17 23:03:50 +00:00
import {writable} from "svelte/store"
2024-10-16 22:57:18 +00:00
import {assoc, sortBy, append} from "@welshman/lib"
2024-10-08 18:39:16 +00:00
import type {EventContent, TrustedEvent} from "@welshman/util"
2024-10-23 23:16:28 +00:00
import {repository} from "@welshman/app"
2024-10-16 22:57:18 +00:00
import type {Thunk} from "@welshman/app"
2024-10-08 18:39:16 +00:00
import {deriveEvents} from "@welshman/store"
import ChannelMessage from "@app/components/ChannelMessage.svelte"
import ChannelCompose from "@app/components/ChannelCompose.svelte"
2024-10-24 20:05:25 +00:00
import {tagRoom, COMMENT} from "@app/state"
import {publishComment} from "@app/commands"
2024-10-01 18:47:21 +00:00
export let url, room, event: TrustedEvent
2024-10-16 22:57:18 +00:00
const thunks = writable({} as Record<string, Thunk>)
2024-10-01 18:47:21 +00:00
const replies = deriveEvents(repository, {
2024-10-24 20:05:25 +00:00
filters: [{kinds: [COMMENT], "#E": [event.id]}],
2024-10-01 18:47:21 +00:00
})
const onSubmit = ({content, tags}: EventContent) => {
2024-10-24 20:05:25 +00:00
const thunk = publishComment({
2024-10-23 21:20:24 +00:00
event,
content,
tags: append(tagRoom(room, url), tags),
relays: [url],
})
2024-10-01 18:47:21 +00:00
2024-10-16 22:57:18 +00:00
thunks.update(assoc(thunk.event.id, thunk))
2024-10-01 18:47:21 +00:00
}
</script>
2024-10-15 22:52:30 +00:00
<div class="col-2">
2024-10-01 18:47:21 +00:00
<div class="overflow-auto pt-3">
2024-10-23 17:20:03 +00:00
<ChannelMessage {url} {room} {event} thunk={$thunks[event.id]} showPubkey isThread />
2024-10-01 18:47:21 +00:00
{#each sortBy(e => e.created_at, $replies) as reply (reply.id)}
2024-10-23 17:20:03 +00:00
<ChannelMessage {url} {room} event={reply} thunk={$thunks[reply.id]} showPubkey />
2024-10-01 18:47:21 +00:00
{/each}
</div>
<div class="bottom-0 left-0 right-0">
2024-10-03 21:43:17 +00:00
<ChannelCompose {onSubmit} />
2024-10-01 18:47:21 +00:00
</div>
</div>