2026-06-23 23:30:54 +00:00
|
|
|
<script lang="ts">
|
2026-09-25 22:55:39 +00:00
|
|
|
import {getAddress} from "@welshman/util"
|
2026-09-17 15:42:56 +00:00
|
|
|
import {publish} from "@welshman/app"
|
2026-07-28 16:16:26 +00:00
|
|
|
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"
|
2026-09-30 17:21:48 +00:00
|
|
|
import UploadMinimalistic from "@assets/icons/upload-minimalistic.svg?dataurl"
|
2026-06-23 23:30:54 +00:00
|
|
|
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"
|
2026-09-30 17:21:48 +00:00
|
|
|
import StringMultiInput from "@lib/components/StringMultiInput.svelte"
|
|
|
|
|
import ImageInputButton from "@app/components/ImageInputButton.svelte"
|
2026-06-23 23:30:54 +00:00
|
|
|
import RelayName from "@app/components/RelayName.svelte"
|
2026-09-25 22:55:39 +00:00
|
|
|
import {command, writer} from "@app/core"
|
2026-09-30 17:21:48 +00:00
|
|
|
import {navigate} from "@app/modal"
|
2026-09-28 17:59:33 +00:00
|
|
|
import {addressWriterToSpace} from "@app/rooms"
|
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"
|
2026-09-30 17:21:48 +00:00
|
|
|
import {resolveImageInput} from "@app/uploads"
|
2026-06-23 23:30:54 +00:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2026-09-30 17:21:48 +00:00
|
|
|
const onImageSelect = (selected: File | string) => {
|
|
|
|
|
if (typeof selected === "string") {
|
|
|
|
|
imageFile = undefined
|
|
|
|
|
image = selected
|
|
|
|
|
} else {
|
|
|
|
|
imageFile = selected
|
|
|
|
|
image = URL.createObjectURL(selected)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const clearImage = () => {
|
|
|
|
|
imageFile = undefined
|
|
|
|
|
image = ""
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 23:30:54 +00:00
|
|
|
const submit = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-09-28 17:59:33 +00:00
|
|
|
const eventWriter = await addressWriterToSpace(
|
2026-09-30 17:21:48 +00:00
|
|
|
writer(Pinboard, board)
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
.setDescription(description)
|
|
|
|
|
.setImage((await resolveImageInput(imageFile, image)) ?? "")
|
|
|
|
|
.setTopics(topics),
|
2026-09-25 22:55:39 +00:00
|
|
|
url,
|
|
|
|
|
)
|
2026-07-28 16:16:26 +00:00
|
|
|
|
|
|
|
|
if (!board) {
|
2026-09-17 15:42:56 +00:00
|
|
|
eventWriter.setIdentifier().setCollaborative(true)
|
2026-07-28 16:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-28 18:45:09 +00:00
|
|
|
const publication = await command(eventWriter).then(publish)
|
|
|
|
|
const error = (await publication.settled()).getError()
|
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-28 18:45:09 +00:00
|
|
|
navigate(makeLibraryPath(url, getAddress(publication.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() ?? "")
|
2026-09-30 17:21:48 +00:00
|
|
|
let topics = $state<string[]>(board?.topics() ?? [])
|
|
|
|
|
let image = $state(board?.image() ?? "")
|
|
|
|
|
let imageFile = $state<File>()
|
2026-07-28 16:16:26 +00:00
|
|
|
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>
|
2026-09-30 17:21:48 +00:00
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Cover image
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<div class="flex items-center gap-3">
|
|
|
|
|
{#if image}
|
|
|
|
|
<img src={image} alt="" class="h-16 w-24 rounded-2xl object-cover" />
|
|
|
|
|
{/if}
|
|
|
|
|
<ImageInputButton
|
|
|
|
|
onSelect={onImageSelect}
|
|
|
|
|
initialValue={imageFile ? undefined : image}
|
|
|
|
|
aria-label="Add a cover image"
|
|
|
|
|
class="button button-neutral button-sm">
|
|
|
|
|
<Icon icon={UploadMinimalistic} size={4} />
|
|
|
|
|
{image ? "Replace" : "Add an image"}
|
|
|
|
|
</ImageInputButton>
|
|
|
|
|
{#if image}
|
|
|
|
|
<Button class="button button-link button-sm" onclick={clearImage}>Remove</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
Topics
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<StringMultiInput bind:value={topics} placeholder="Add a topic..." />
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
2026-06-23 23:30:54 +00:00
|
|
|
</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>
|