flotilla/src/app/components/ThreadActions.svelte

94 lines
3.3 KiB
Svelte
Raw Normal View History

2024-10-23 23:16:28 +00:00
<script lang="ts">
2024-11-15 22:03:54 +00:00
import {onMount} from "svelte"
2024-10-23 23:16:28 +00:00
import {type Instance} from "tippy.js"
import type {NativeEmoji} from "emoji-picker-element/shared"
import {max} from "@welshman/lib"
2024-10-24 18:52:02 +00:00
import {deriveEvents, deriveIsDeleted} from "@welshman/store"
2024-10-23 23:16:28 +00:00
import type {TrustedEvent} from "@welshman/util"
2024-11-15 22:03:54 +00:00
import {thunks, load, pubkey, repository, formatTimestampRelative} from "@welshman/app"
2024-10-23 23:16:28 +00:00
import Icon from "@lib/components/Icon.svelte"
import Tippy from "@lib/components/Tippy.svelte"
import Button from "@lib/components/Button.svelte"
import EmojiButton from "@lib/components/EmojiButton.svelte"
import ReactionSummary from "@app/components/ReactionSummary.svelte"
2024-11-12 22:32:36 +00:00
import ThunkStatus from "@app/components/ThunkStatus.svelte"
2024-10-23 23:16:28 +00:00
import ThreadMenu from "@app/components/ThreadMenu.svelte"
import {publishDelete, publishReaction} from "@app/commands"
2024-11-14 18:53:13 +00:00
import {deriveNotification} from "@app/notifications"
import {makeSpacePath} from "@app/routes"
2024-10-24 20:05:25 +00:00
import {COMMENT} from "@app/state"
2024-10-23 23:16:28 +00:00
export let url
export let event
export let showActivity = false
2024-11-12 22:32:36 +00:00
const thunk = $thunks[event.id]
2024-10-24 18:52:02 +00:00
const deleted = deriveIsDeleted(repository, event)
2024-11-14 18:53:13 +00:00
const path = makeSpacePath(url, "threads", event.id)
const filters = [{kinds: [COMMENT], "#E": [event.id]}]
const replies = deriveEvents(repository, {filters})
2024-11-15 22:03:54 +00:00
const notification = deriveNotification(path, filters, url)
2024-10-23 23:16:28 +00:00
const showPopover = () => popover.show()
const hidePopover = () => popover.hide()
const onReactionClick = (content: string, events: TrustedEvent[]) => {
const reaction = events.find(e => e.pubkey === $pubkey)
if (reaction) {
publishDelete({relays: [url], event: reaction})
} else {
publishReaction({event, content, relays: [url]})
}
}
const onEmoji = (emoji: NativeEmoji) =>
publishReaction({event, relays: [url], content: emoji.unicode})
let popover: Instance
$: lastActive = max([...$replies, event].map(e => e.created_at))
2024-11-15 22:03:54 +00:00
onMount(() => {
load({relays: [url], filters})
})
2024-10-23 23:16:28 +00:00
</script>
2024-10-24 16:58:43 +00:00
<div class="flex flex-wrap items-center justify-between gap-2">
2024-10-31 19:24:40 +00:00
<div class="flex flex-grow flex-wrap justify-end gap-2">
2024-11-20 23:56:24 +00:00
<ReactionSummary relays={[url]} {event} {onReactionClick} />
2024-10-24 18:52:02 +00:00
{#if $deleted}
<div class="btn btn-error btn-xs rounded-full">Deleted</div>
2024-11-12 22:32:36 +00:00
{:else if thunk}
<ThunkStatus {thunk} />
2024-10-24 18:52:02 +00:00
{/if}
{#if showActivity}
<div class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full">
<Icon icon="reply" />
<span>{$replies.length} {$replies.length === 1 ? "reply" : "replies"}</span>
</div>
2024-11-14 18:53:13 +00:00
<div class="btn btn-neutral btn-xs relative hidden rounded-full sm:flex">
{#if $notification}
<div class="h-2 w-2 rounded-full bg-primary" />
{/if}
Active {formatTimestampRelative(lastActive)}
</div>
{/if}
2024-10-24 17:11:01 +00:00
<Button class="join rounded-full">
2024-10-24 22:48:45 +00:00
<EmojiButton {onEmoji} class="btn join-item btn-neutral btn-xs">
<Icon icon="smile-circle" size={4} />
</EmojiButton>
<Tippy
bind:popover
component={ThreadMenu}
props={{url, event, onClick: hidePopover}}
params={{trigger: "manual", interactive: true}}>
2024-10-24 16:58:43 +00:00
<Button class="btn join-item btn-neutral btn-xs" on:click={showPopover}>
<Icon icon="menu-dots" size={4} />
</Button>
</Tippy>
2024-10-24 17:11:01 +00:00
</Button>
2024-10-23 23:16:28 +00:00
</div>
</div>