forked from coracle/flotilla
Get threads working reasonably well
This commit is contained in:
+3
-3
@@ -17,7 +17,7 @@ import {
|
|||||||
tagEvent,
|
tagEvent,
|
||||||
tagReactionTo,
|
tagReactionTo,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import {ROOM, MEMBERSHIPS, INDEXER_RELAYS} from "@app/state"
|
import {tagRoom, MEMBERSHIPS, INDEXER_RELAYS} from "@app/state"
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ export const addSpaceMembership = (url: string) =>
|
|||||||
|
|
||||||
export const addRoomMembership = (url: string, room: string) =>
|
export const addRoomMembership = (url: string, room: string) =>
|
||||||
updateList(MEMBERSHIPS, (tags: string[][]) =>
|
updateList(MEMBERSHIPS, (tags: string[][]) =>
|
||||||
uniqBy(t => t.join(""), [...tags, [ROOM, room, url]]),
|
uniqBy(t => t.join(""), [...tags, tagRoom(room, url)]),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const removeSpaceMembership = (url: string) =>
|
export const removeSpaceMembership = (url: string) =>
|
||||||
@@ -108,7 +108,7 @@ export const removeSpaceMembership = (url: string) =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const removeRoomMembership = (url: string, room: string) =>
|
export const removeRoomMembership = (url: string, room: string) =>
|
||||||
updateList(MEMBERSHIPS, (tags: string[][]) => tags.filter(t => !equals([ROOM, room, url], t)))
|
updateList(MEMBERSHIPS, (tags: string[][]) => tags.filter(t => !equals(tagRoom(room, url), t)))
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
|
|||||||
@@ -8,24 +8,21 @@
|
|||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import {getEditorOptions, getEditorTags, addFile} from "@lib/editor"
|
import {getEditorOptions, getEditorTags, addFile} from "@lib/editor"
|
||||||
import {ROOM, MESSAGE, GENERAL} from "@app/state"
|
import {MESSAGE} from "@app/state"
|
||||||
import {getPubkeyHints} from "@app/commands"
|
import {getPubkeyHints} from "@app/commands"
|
||||||
|
|
||||||
export let url
|
export let onSubmit
|
||||||
export let room = GENERAL
|
|
||||||
|
|
||||||
const loading = writable(false)
|
const loading = writable(false)
|
||||||
|
|
||||||
let editor: Readable<Editor>
|
let editor: Readable<Editor>
|
||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
const event = createEvent(MESSAGE, {
|
onSubmit({
|
||||||
content: $editor.getText(),
|
content: $editor.getText(),
|
||||||
tags: [[ROOM, room], ...getEditorTags($editor)],
|
tags: getEditorTags($editor),
|
||||||
})
|
})
|
||||||
|
|
||||||
publishThunk(makeThunk({event, relays: [url]}))
|
|
||||||
|
|
||||||
$editor.chain().clearContent().run()
|
$editor.chain().clearContent().run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,8 +31,7 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class="relative z-feature flex gap-2 p-2">
|
||||||
class="shadow-top-xl relative z-feature flex gap-2 border-t border-solid border-base-100 bg-base-100 p-2">
|
|
||||||
<Button
|
<Button
|
||||||
data-tip="Add an image"
|
data-tip="Add an image"
|
||||||
class="center tooltip h-10 w-10 rounded-box bg-base-300 transition-colors hover:bg-base-200"
|
class="center tooltip h-10 w-10 rounded-box bg-base-300 transition-colors hover:bg-base-200"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import twColors from "tailwindcss/colors"
|
import twColors from "tailwindcss/colors"
|
||||||
import type {Readable} from "svelte/store"
|
import type {Readable} from "svelte/store"
|
||||||
import {readable, derived} from "svelte/store"
|
import {readable, derived} from "svelte/store"
|
||||||
import {hash, uniqBy, groupBy, now} from "@welshman/lib"
|
import {hash, ellipsize, uniqBy, groupBy, now} from "@welshman/lib"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {deriveEvents} from "@welshman/store"
|
import {deriveEvents} from "@welshman/store"
|
||||||
import {PublishStatus} from "@welshman/net"
|
import {PublishStatus} from "@welshman/net"
|
||||||
@@ -23,23 +23,21 @@
|
|||||||
import type {PublishStatusData} from "@welshman/app"
|
import type {PublishStatusData} from "@welshman/app"
|
||||||
import {REACTION, DELETE, ZAP_RESPONSE, createEvent, displayRelayUrl, getAncestorTags} from "@welshman/util"
|
import {REACTION, DELETE, ZAP_RESPONSE, createEvent, displayRelayUrl, getAncestorTags} from "@welshman/util"
|
||||||
import {repository} from "@welshman/app"
|
import {repository} from "@welshman/app"
|
||||||
import {fly} from "@lib/transition"
|
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Avatar from "@lib/components/Avatar.svelte"
|
import Avatar from "@lib/components/Avatar.svelte"
|
||||||
import Drawer from "@lib/components/Drawer.svelte"
|
|
||||||
import Content from "@app/components/Content.svelte"
|
import Content from "@app/components/Content.svelte"
|
||||||
|
import ChatThread from '@app/components/ChatThread.svelte'
|
||||||
import ChatMessageEmojiButton from "@app/components/ChatMessageEmojiButton.svelte"
|
import ChatMessageEmojiButton from "@app/components/ChatMessageEmojiButton.svelte"
|
||||||
import ChatMessageReplies from "@app/components/ChatMessageReplies.svelte"
|
import {tagRoom, REPLY, deriveEvent, displayReaction} from "@app/state"
|
||||||
import ChatMessageReply from "@app/components/ChatMessageReply.svelte"
|
|
||||||
import {ROOM, REPLY, deriveEvent, displayReaction} from "@app/state"
|
|
||||||
import {publishDelete, publishReaction} from "@app/commands"
|
import {publishDelete, publishReaction} from "@app/commands"
|
||||||
|
import {pushModal} from '@app/modal'
|
||||||
|
|
||||||
export let url
|
export let url
|
||||||
export let room
|
export let room
|
||||||
export let event: TrustedEvent
|
export let event: TrustedEvent
|
||||||
export let showPubkey: boolean
|
export let showPubkey = false
|
||||||
export let isReply = false
|
export let hideParent = false
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
["amber", twColors.amber[600]],
|
["amber", twColors.amber[600]],
|
||||||
@@ -67,16 +65,21 @@
|
|||||||
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
||||||
const reactions = deriveEvents(repository, {filters: [{kinds: [REACTION], "#e": [event.id]}]})
|
const reactions = deriveEvents(repository, {filters: [{kinds: [REACTION], "#e": [event.id]}]})
|
||||||
const zaps = deriveEvents(repository, {filters: [{kinds: [ZAP_RESPONSE], "#e": [event.id]}]})
|
const zaps = deriveEvents(repository, {filters: [{kinds: [ZAP_RESPONSE], "#e": [event.id]}]})
|
||||||
const {replies} = getAncestorTags(event.tags)
|
const rootTag = event.tags.find(t => t[0].match(/^e$/i))
|
||||||
const parentId = replies[0]?.[1]
|
const rootId = rootTag?.[1]
|
||||||
const parentHints = [replies[0]?.[2]].filter(Boolean)
|
const rootHints = [rootTag?.[2]].filter(Boolean) as string[]
|
||||||
const parentEvent = parentId ? deriveEvent(parentId, parentHints) : readable(null)
|
const rootEvent = rootId ? deriveEvent(rootId, rootHints) : readable(null)
|
||||||
const [colorName, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
const [colorName, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
||||||
const ps = derived(publishStatusData, $m => Object.values($m[event.id] || {}))
|
const ps = derived(publishStatusData, $m => Object.values($m[event.id] || {}))
|
||||||
|
|
||||||
const findStatus = ($ps: PublishStatusData[], statuses: PublishStatus[]) =>
|
const findStatus = ($ps: PublishStatusData[], statuses: PublishStatus[]) =>
|
||||||
$ps.find(({status}) => statuses.includes(status))
|
$ps.find(({status}) => statuses.includes(status))
|
||||||
|
|
||||||
|
const openThread = () => {
|
||||||
|
const root = $rootEvent || event
|
||||||
|
|
||||||
|
pushModal(ChatThread, {url, room, event: root}, {drawer: true})
|
||||||
|
}
|
||||||
|
|
||||||
const onReactionClick = (content: string, events: TrustedEvent[]) => {
|
const onReactionClick = (content: string, events: TrustedEvent[]) => {
|
||||||
const reaction = events.find(e => e.pubkey === $pubkey)
|
const reaction = events.find(e => e.pubkey === $pubkey)
|
||||||
@@ -88,37 +91,32 @@
|
|||||||
event,
|
event,
|
||||||
content,
|
content,
|
||||||
relays: [url],
|
relays: [url],
|
||||||
tags: [[ROOM, room, url]],
|
tags: [tagRoom(room, url)],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let drawer: SvelteComponent
|
let drawer: SvelteComponent
|
||||||
|
|
||||||
$: parentPubkey = $parentEvent?.pubkey || replies[0]?.[4]
|
$: rootPubkey = $rootEvent?.pubkey || rootTag?.[4]
|
||||||
$: parentProfile = deriveProfile(parentPubkey || "")
|
$: rootProfile = deriveProfile(rootPubkey || "")
|
||||||
$: parentProfileDisplay = deriveProfileDisplay(parentPubkey || "")
|
$: rootProfileDisplay = deriveProfileDisplay(rootPubkey || "")
|
||||||
$: isPublished = findStatus($ps, [PublishStatus.Success])
|
$: isPublished = findStatus($ps, [PublishStatus.Success])
|
||||||
$: isPending = findStatus($ps, [PublishStatus.Pending]) && event.created_at > now() - 30
|
$: isPending = findStatus($ps, [PublishStatus.Pending]) && event.created_at > now() - 30
|
||||||
$: failure =
|
$: failure =
|
||||||
!isPending && !isPublished && findStatus($ps, [PublishStatus.Failure, PublishStatus.Timeout])
|
!isPending && !isPublished && findStatus($ps, [PublishStatus.Failure, PublishStatus.Timeout])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<button type="button" on:click={openThread} class="group relative flex flex-col gap-1 p-2 transition-colors hover:bg-base-300 text-left w-full">
|
||||||
in:fly
|
{#if $rootEvent && !hideParent}
|
||||||
class="group relative flex flex-col gap-1 p-2 transition-colors"
|
|
||||||
class:hover:bg-base-300={!isReply}
|
|
||||||
class:mt-4={isReply}>
|
|
||||||
{#if event.kind === REPLY}
|
|
||||||
<div class="flex items-center gap-1 pl-12 text-xs">
|
<div class="flex items-center gap-1 pl-12 text-xs">
|
||||||
<Icon icon="arrow-right" />
|
<Icon icon="square-share-line" size={3} />
|
||||||
<Avatar src={$parentProfile?.picture} size={4} />
|
<p>In reply to</p>
|
||||||
<p class="text-primary">{$parentProfileDisplay}</p>
|
<Avatar src={$rootProfile?.picture} size={4} />
|
||||||
<p></p>
|
<p class="text-primary">{$rootProfileDisplay}</p>
|
||||||
<p
|
<p
|
||||||
class="flex cursor-pointer items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap opacity-75 hover:underline">
|
class="flex items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap opacity-75 hover:underline">
|
||||||
<Icon icon="square-share-line" size={3} />
|
{ellipsize($rootEvent.content, 30)}
|
||||||
{$parentEvent?.content || "View note"}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -157,33 +155,29 @@
|
|||||||
{#if $reactions.length > 0 || $zaps.length > 0}
|
{#if $reactions.length > 0 || $zaps.length > 0}
|
||||||
<div class="ml-12 text-xs">
|
<div class="ml-12 text-xs">
|
||||||
{#each groupBy(e => e.content, uniqBy(e => e.pubkey + e.content, $reactions)).entries() as [content, events]}
|
{#each groupBy(e => e.content, uniqBy(e => e.pubkey + e.content, $reactions)).entries() as [content, events]}
|
||||||
<Button class="flex-inline btn btn-neutral btn-xs mr-2 gap-1 rounded-full" on:click={() => onReactionClick(content, events)}>
|
{@const isOwn = events.some(e => e.pubkey === $pubkey)}
|
||||||
|
{@const onClick = () => onReactionClick(content, events)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex-inline btn btn-neutral btn-xs mr-2 gap-1 rounded-full"
|
||||||
|
class:border={isOwn}
|
||||||
|
class:border-solid={isOwn}
|
||||||
|
class:border-primary={isOwn}
|
||||||
|
on:click|stopPropagation={onClick}>
|
||||||
<span>{displayReaction(content)}</span>
|
<span>{displayReaction(content)}</span>
|
||||||
{#if events.length > 1}
|
{#if events.length > 1}
|
||||||
<span>{events.length}</span>
|
<span>{events.length}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<button
|
||||||
class="join absolute -top-2 right-0 border border-solid border-neutral text-xs opacity-0 transition-all group-hover:opacity-100">
|
class="join absolute -top-2 right-0 border border-solid border-neutral text-xs opacity-0 transition-all group-hover:opacity-100"
|
||||||
{#if !isReply}
|
on:click|stopPropagation>
|
||||||
<button class="btn join-item btn-xs" on:click={() => drawer.open()}>
|
|
||||||
<Icon icon="reply" size={4} />
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
<ChatMessageEmojiButton {url} {room} {event} />
|
<ChatMessageEmojiButton {url} {room} {event} />
|
||||||
<button class="btn join-item btn-xs">
|
<button class="btn join-item btn-xs">
|
||||||
<Icon icon="menu-dots" size={4} />
|
<Icon icon="menu-dots" size={4} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</button>
|
||||||
|
|
||||||
{#if !isReply}
|
|
||||||
<Drawer bind:this={drawer}>
|
|
||||||
<svelte:self {...$$props} isReply />
|
|
||||||
<ChatMessageReplies {url} {room} {event} />
|
|
||||||
<ChatMessageReply {url} {room} {event} />
|
|
||||||
</Drawer>
|
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Tippy from "@lib/components/Tippy.svelte"
|
import Tippy from "@lib/components/Tippy.svelte"
|
||||||
import EmojiPicker from "@lib/components/EmojiPicker.svelte"
|
import EmojiPicker from "@lib/components/EmojiPicker.svelte"
|
||||||
import {ROOM} from '@app/state'
|
import {tagRoom} from '@app/state'
|
||||||
import {publishReaction} from '@app/commands'
|
import {publishReaction} from '@app/commands'
|
||||||
|
|
||||||
export let url, room, event
|
export let url, room, event
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
event,
|
event,
|
||||||
relays: [url],
|
relays: [url],
|
||||||
content: emoji.unicode,
|
content: emoji.unicode,
|
||||||
tags: [[ROOM, room, url]],
|
tags: [tagRoom(room, url)],
|
||||||
})
|
})
|
||||||
|
|
||||||
popover.hide()
|
popover.hide()
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
hi
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
hi
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {sortBy, append, range} from '@welshman/lib'
|
||||||
|
import {createEvent} from '@welshman/util'
|
||||||
|
import type {EventContent, TrustedEvent} from '@welshman/util'
|
||||||
|
import {repository, makeThunk, publishThunk} from '@welshman/app'
|
||||||
|
import {deriveEvents} from '@welshman/store'
|
||||||
|
import ChatMessage from '@app/components/ChatMessage.svelte'
|
||||||
|
import ChatCompose from '@app/components/ChatCompose.svelte'
|
||||||
|
import {tagRoom, REPLY} from '@app/state'
|
||||||
|
|
||||||
|
export let url, room, event: TrustedEvent
|
||||||
|
|
||||||
|
const replies = deriveEvents(repository, {
|
||||||
|
filters: [{kinds: [REPLY], '#E': [event.id]}],
|
||||||
|
})
|
||||||
|
|
||||||
|
const onSubmit = ({content, tags}: EventContent) => {
|
||||||
|
const seenRoots = new Set<string>()
|
||||||
|
|
||||||
|
for (const [raw, ...tag] of event.tags.filter(t => t[0].match(/^K|E|A|I$/i))) {
|
||||||
|
const T = raw.toUpperCase()
|
||||||
|
const t = raw.toLowerCase()
|
||||||
|
|
||||||
|
if (seenRoots.has(T)) {
|
||||||
|
tags.push([t, ...tag])
|
||||||
|
} else {
|
||||||
|
tags.push([T, ...tag])
|
||||||
|
seenRoots.add(T)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seenRoots.size === 0) {
|
||||||
|
tags.push(['K', String(event.kind)])
|
||||||
|
tags.push(['E', event.id])
|
||||||
|
} else {
|
||||||
|
tags.push(['k', String(event.kind)])
|
||||||
|
tags.push(['e', event.id])
|
||||||
|
}
|
||||||
|
|
||||||
|
const reply = createEvent(REPLY, {content, tags: append(tagRoom(room, url), tags)})
|
||||||
|
|
||||||
|
publishThunk(makeThunk({event: reply, relays: [url]}))
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="fixed flex flex-col max-h-screen w-full gap-2">
|
||||||
|
<div class="overflow-auto pt-3">
|
||||||
|
<ChatMessage {url} {room} {event} showPubkey />
|
||||||
|
{#each sortBy(e => e.created_at, $replies) as reply (reply.id)}
|
||||||
|
<ChatMessage {url} {room} event={reply} showPubkey hideParent />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<div class="bottom-0 left-0 right-0">
|
||||||
|
<ChatCompose {onSubmit} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+6
-2
@@ -6,11 +6,15 @@ export const emitter = new Emitter()
|
|||||||
|
|
||||||
export const modals = new Map()
|
export const modals = new Map()
|
||||||
|
|
||||||
export const pushModal = (component: ComponentType, props: Record<string, any> = {}) => {
|
export type ModalOptions = {
|
||||||
|
drawer?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pushModal = (component: ComponentType, props: Record<string, any> = {}, options: ModalOptions = {}) => {
|
||||||
const id = randomId()
|
const id = randomId()
|
||||||
|
|
||||||
// TODO: fix memory leak here by listening to history somehow
|
// TODO: fix memory leak here by listening to history somehow
|
||||||
modals.set(id, {component, props})
|
modals.set(id, {component, props, options})
|
||||||
goto("#" + id)
|
goto("#" + id)
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ export const imgproxy = (url: string, {w = 640, h = 1024} = {}) => {
|
|||||||
|
|
||||||
export const entityLink = (entity: string) => `https://coracle.social/${entity}`
|
export const entityLink = (entity: string) => `https://coracle.social/${entity}`
|
||||||
|
|
||||||
|
export const tagRoom = (room: string, url: string) => [ROOM, room, url]
|
||||||
|
|
||||||
setContext({
|
setContext({
|
||||||
net: getDefaultNetContext(),
|
net: getDefaultNetContext(),
|
||||||
app: getDefaultAppContext({
|
app: getDefaultAppContext({
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="drawer-side z-modal">
|
<div class="drawer-side z-modal">
|
||||||
<label for={id} aria-label="close sidebar" class="drawer-overlay"></label>
|
<label for={id} aria-label="close sidebar" class="drawer-overlay"></label>
|
||||||
<div class="menu bg-base-200 text-base-content min-h-full w-80">
|
<div class="menu bg-base-200 text-base-content min-h-full w-80 p-0">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import "@src/app.css"
|
import "@src/app.css"
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
|
import type {SvelteComponent} from "svelte"
|
||||||
import {get} from "svelte/store"
|
import {get} from "svelte/store"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import * as app from "@welshman/app"
|
import * as app from "@welshman/app"
|
||||||
import ModalBox from "@lib/components/ModalBox.svelte"
|
import ModalBox from "@lib/components/ModalBox.svelte"
|
||||||
|
import Drawer from "@lib/components/Drawer.svelte"
|
||||||
import Toast from "@app/components/Toast.svelte"
|
import Toast from "@app/components/Toast.svelte"
|
||||||
import Landing from "@app/components/Landing.svelte"
|
import Landing from "@app/components/Landing.svelte"
|
||||||
import PrimaryNav from "@app/components/PrimaryNav.svelte"
|
import PrimaryNav from "@app/components/PrimaryNav.svelte"
|
||||||
@@ -35,6 +37,7 @@
|
|||||||
|
|
||||||
let ready: Promise<unknown>
|
let ready: Promise<unknown>
|
||||||
let dialog: HTMLDialogElement
|
let dialog: HTMLDialogElement
|
||||||
|
let drawer: SvelteComponent
|
||||||
let prev: any
|
let prev: any
|
||||||
|
|
||||||
$: modalId = $page.url.hash.slice(1)
|
$: modalId = $page.url.hash.slice(1)
|
||||||
@@ -52,9 +55,15 @@
|
|||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (modal) {
|
if (modal) {
|
||||||
dialog?.showModal()
|
|
||||||
prev = modal
|
prev = modal
|
||||||
|
|
||||||
|
if (prev.options.drawer) {
|
||||||
|
drawer?.open()
|
||||||
|
} else {
|
||||||
|
dialog?.showModal()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
drawer?.close()
|
||||||
dialog?.close()
|
dialog?.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +110,7 @@
|
|||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
<dialog bind:this={dialog} class="modal modal-bottom !z-modal sm:modal-middle">
|
<dialog bind:this={dialog} class="modal modal-bottom !z-modal sm:modal-middle">
|
||||||
{#if prev}
|
{#if prev && !prev.options.drawer}
|
||||||
{#key prev}
|
{#key prev}
|
||||||
<ModalBox {...prev} />
|
<ModalBox {...prev} />
|
||||||
{/key}
|
{/key}
|
||||||
@@ -113,6 +122,13 @@
|
|||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
</dialog>
|
</dialog>
|
||||||
|
<Drawer bind:this={drawer}>
|
||||||
|
{#if prev && prev.options.drawer}
|
||||||
|
{#key prev}
|
||||||
|
<svelte:component this={prev.component} {...prev.props} />
|
||||||
|
{/key}
|
||||||
|
{/if}
|
||||||
|
</Drawer>
|
||||||
<Toast />
|
<Toast />
|
||||||
</div>
|
</div>
|
||||||
{/await}
|
{/await}
|
||||||
|
|||||||
@@ -9,16 +9,18 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {sortBy} from "@welshman/lib"
|
import {sortBy, append} from "@welshman/lib"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent, EventContent} from "@welshman/util"
|
||||||
import {formatTimestampAsDate} from "@welshman/app"
|
import {createEvent} from "@welshman/util"
|
||||||
|
import {formatTimestampAsDate, makeThunk, publishThunk} from "@welshman/app"
|
||||||
|
import {fly} from "@lib/transition"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import Divider from "@lib/components/Divider.svelte"
|
import Divider from "@lib/components/Divider.svelte"
|
||||||
import ChatMessage from "@app/components/ChatMessage.svelte"
|
import ChatMessage from "@app/components/ChatMessage.svelte"
|
||||||
import ChatCompose from "@app/components/ChatCompose.svelte"
|
import ChatCompose from "@app/components/ChatCompose.svelte"
|
||||||
import {userMembership, decodeNRelay, makeChatId, deriveChat, GENERAL} from "@app/state"
|
import {userMembership, decodeNRelay, makeChatId, deriveChat, GENERAL, tagRoom, MESSAGE} from "@app/state"
|
||||||
import {addRoomMembership, removeRoomMembership} from "@app/commands"
|
import {addRoomMembership, removeRoomMembership} from "@app/commands"
|
||||||
|
|
||||||
const {nrelay, room = GENERAL} = $page.params
|
const {nrelay, room = GENERAL} = $page.params
|
||||||
@@ -27,6 +29,12 @@
|
|||||||
|
|
||||||
const assertEvent = (e: any) => e as TrustedEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
||||||
|
const onSubmit = ({content, tags}: EventContent) => {
|
||||||
|
const event = createEvent(MESSAGE, {content, tags: append(tagRoom(room, url), tags)})
|
||||||
|
|
||||||
|
publishThunk(makeThunk({event, relays: [url]}))
|
||||||
|
}
|
||||||
|
|
||||||
let loading = true
|
let loading = true
|
||||||
let elements: Element[] = []
|
let elements: Element[] = []
|
||||||
|
|
||||||
@@ -93,7 +101,9 @@
|
|||||||
{#if type === "date"}
|
{#if type === "date"}
|
||||||
<Divider>{value}</Divider>
|
<Divider>{value}</Divider>
|
||||||
{:else}
|
{:else}
|
||||||
<ChatMessage {url} {room} event={assertEvent(value)} {showPubkey} />
|
<div in:fly>
|
||||||
|
<ChatMessage {url} {room} event={assertEvent(value)} {showPubkey} />
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
<p class="flex h-10 items-center justify-center py-20">
|
<p class="flex h-10 items-center justify-center py-20">
|
||||||
@@ -106,5 +116,7 @@
|
|||||||
</Spinner>
|
</Spinner>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<ChatCompose {url} {room} />
|
<div class="shadow-top-xl border-t border-solid border-base-100 bg-base-100">
|
||||||
|
<ChatCompose {onSubmit} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user