2026-06-23 23:30:54 +00:00
|
|
|
<script lang="ts">
|
2026-09-08 17:23:22 +00:00
|
|
|
import {navigate} from "@app/modal"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {getAddress} from "@welshman/util"
|
|
|
|
|
import {publishAsRelay} from "@welshman/app"
|
|
|
|
|
import {Pinboard} from "@welshman/domain"
|
|
|
|
|
import type {PinboardReader} from "@welshman/domain"
|
2026-06-23 23:30:54 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Field from "@lib/components/Field.svelte"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
|
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
|
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
|
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
|
|
|
|
import RelayName from "@app/components/RelayName.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {command, writer} from "@app/core"
|
2026-07-08 17:29:56 +00:00
|
|
|
import {makeLibraryPath} from "@app/routes"
|
2026-06-23 23:30:54 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
2026-07-28 16:16:26 +00:00
|
|
|
board?: PinboardReader
|
2026-06-23 23:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const {url, board}: Props = $props()
|
2026-06-23 23:30:54 +00:00
|
|
|
|
|
|
|
|
const back = () => history.back()
|
|
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-28 16:16:26 +00:00
|
|
|
const eventWriter = writer(Pinboard, board).setTitle(title).setDescription(description)
|
|
|
|
|
|
|
|
|
|
if (!board) {
|
|
|
|
|
eventWriter.setIdentifier()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const thunk = await command(eventWriter).then(publishAsRelay(url))
|
|
|
|
|
const error = await thunk.waitForError()
|
2026-06-23 23:30:54 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
2026-07-28 16:16:26 +00:00
|
|
|
} else if (board) {
|
|
|
|
|
pushToast({message: "Shelf updated!"})
|
|
|
|
|
back()
|
2026-06-23 23:30:54 +00:00
|
|
|
} else {
|
2026-07-28 16:16:26 +00:00
|
|
|
pushToast({message: "Shelf created!"})
|
2026-09-08 17:23:22 +00:00
|
|
|
navigate(makeLibraryPath(url, getAddress(thunk.event)))
|
2026-06-23 23:30:54 +00:00
|
|
|
}
|
2026-07-28 16:16:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
pushToast({theme: "error", message: "This space refused to save the shelf."})
|
2026-06-23 23:30:54 +00:00
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-28 16:16:26 +00:00
|
|
|
|
|
|
|
|
let title = $state(board?.title() ?? "")
|
|
|
|
|
let description = $state(board?.description() ?? "")
|
|
|
|
|
let loading = $state(false)
|
2026-06-23 23:30:54 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
2026-07-28 16:16:26 +00:00
|
|
|
<ModalTitle>{board ? "Edit Shelf" : "Create Shelf"}</ModalTitle>
|
2026-06-23 23:30:54 +00:00
|
|
|
<ModalSubtitle>on <RelayName {url} class="text-primary" /></ModalSubtitle>
|
|
|
|
|
</ModalHeader>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Title
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
2026-07-27 22:38:23 +00:00
|
|
|
<input bind:value={title} class="input w-full" placeholder="Shelf title" />
|
2026-06-23 23:30:54 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Description
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<input
|
|
|
|
|
bind:value={description}
|
2026-07-27 22:38:23 +00:00
|
|
|
class="input w-full"
|
2026-06-23 23:30:54 +00:00
|
|
|
placeholder="What's this shelf about?" />
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<Button class="button button-link" onclick={back}>
|
|
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
|
|
|
|
<Button class="button button-primary" onclick={submit} disabled={loading || !title.trim()}>
|
|
|
|
|
<Spinner {loading}>Save changes</Spinner>
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|