2026-07-08 17:29:56 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import type {PinboardReader} from "@welshman/domain"
|
2026-08-14 23:06:17 +00:00
|
|
|
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
|
|
|
|
import Pen from "@assets/icons/pen.svg?dataurl"
|
|
|
|
|
import TrashBin from "@assets/icons/trash-bin-2.svg?dataurl"
|
2026-07-08 17:29:56 +00:00
|
|
|
import ShareCircle from "@assets/icons/share-circle.svg?dataurl"
|
|
|
|
|
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
2026-08-14 23:06:17 +00:00
|
|
|
import {errorMessage} from "@lib/util"
|
2026-07-08 17:29:56 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-08-14 23:06:17 +00:00
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2026-07-08 17:29:56 +00:00
|
|
|
import EventInfo from "@app/components/EventInfo.svelte"
|
2026-08-14 23:06:17 +00:00
|
|
|
import PinAdd from "@app/components/PinAdd.svelte"
|
|
|
|
|
import PinboardEdit from "@app/components/PinboardEdit.svelte"
|
2026-09-17 15:42:56 +00:00
|
|
|
import {deletes, relays, user} from "@app/core"
|
2026-08-11 21:54:05 +00:00
|
|
|
import {shareEvent} from "@app/share"
|
2026-07-08 17:29:56 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2026-08-14 23:06:17 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-07-08 17:29:56 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
2026-07-28 16:16:26 +00:00
|
|
|
board: PinboardReader
|
2026-07-08 17:29:56 +00:00
|
|
|
onClick: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, board, onClick}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const showInfo = () => pushModal(EventInfo, {url, event: board.event})
|
|
|
|
|
|
2026-08-11 21:54:05 +00:00
|
|
|
const share = () => shareEvent(url, "Shelf", board.event)
|
2026-07-08 17:29:56 +00:00
|
|
|
|
2026-08-14 23:06:17 +00:00
|
|
|
const addLink = () => pushModal(PinAdd, {url, address: board.address()})
|
|
|
|
|
|
|
|
|
|
const edit = () => pushModal(PinboardEdit, {url, board})
|
|
|
|
|
|
|
|
|
|
const deleteBoard = async () => {
|
|
|
|
|
try {
|
2026-09-17 15:42:56 +00:00
|
|
|
const protect = await $relays.hasNip(url, 70)
|
|
|
|
|
const command = await $deletes.deleteEvent(board.event, writer =>
|
|
|
|
|
writer.setProtected(protect),
|
|
|
|
|
)
|
|
|
|
|
const error = await command.publishToRelays([url]).waitForError()
|
2026-08-14 23:06:17 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "Shelf deleted!"})
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
pushToast({theme: "error", message: errorMessage(e)})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const confirmDelete = () =>
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: "Delete Shelf",
|
|
|
|
|
message: `Delete "${board.title() || "this shelf"}"?`,
|
|
|
|
|
confirm: deleteBoard,
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-08 17:29:56 +00:00
|
|
|
let ul: Element
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
ul.addEventListener("click", onClick)
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<ul class="menu whitespace-nowrap rounded-2xl bg-surface p-2" bind:this={ul}>
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={showInfo}>
|
|
|
|
|
<Icon icon={Code2} />
|
|
|
|
|
Shelf details
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={share}>
|
|
|
|
|
<Icon icon={ShareCircle} />
|
|
|
|
|
Share to chat
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
2026-09-17 15:42:56 +00:00
|
|
|
<li>
|
|
|
|
|
<Button onclick={addLink}>
|
|
|
|
|
<Icon icon={AddCircle} />
|
|
|
|
|
Add link
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{#if board.event.pubkey === $user.pubkey}
|
2026-08-14 23:06:17 +00:00
|
|
|
<li>
|
|
|
|
|
<Button onclick={edit}>
|
|
|
|
|
<Icon icon={Pen} />
|
|
|
|
|
Edit shelf
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={confirmDelete}>
|
|
|
|
|
<Icon icon={TrashBin} />
|
|
|
|
|
Delete shelf
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-07-08 17:29:56 +00:00
|
|
|
</ul>
|