flotilla/src/app/components/PinEdit.svelte

43 lines
1.1 KiB
Svelte
Raw Normal View History

2026-06-23 23:30:54 +00:00
<script lang="ts">
2026-07-28 16:16:26 +00:00
import {Pin} from "@welshman/domain"
import {publishAsRelay} from "@welshman/app"
import type {PinReader} from "@welshman/domain"
2026-06-23 23:30:54 +00:00
import PinForm, {type PinFormValues} from "@app/components/PinForm.svelte"
2026-07-28 16:16:26 +00:00
import {command, writer} from "@app/core"
import {pinToReference, setPinReference} from "@app/pinboards"
2026-06-23 23:30:54 +00:00
type Props = {
url: string
2026-07-28 16:16:26 +00:00
pin: PinReader
2026-06-23 23:30:54 +00:00
}
const {url, pin}: Props = $props()
2026-07-06 18:53:12 +00:00
const submit = async ({title, topics, value, content}: PinFormValues) => {
2026-07-28 16:16:26 +00:00
const eventWriter = writer(Pin, pin)
if (!setPinReference(eventWriter, value)) {
return "Please enter a valid URL or nostr link."
}
eventWriter.setTitle(title).setTopics(topics).setContent(content)
const thunk = await command(eventWriter).then(publishAsRelay(url))
return thunk.waitForError()
2026-06-23 23:30:54 +00:00
}
</script>
<PinForm
{url}
heading="Edit Link"
action="Save changes"
successMessage="Link updated!"
2026-07-06 18:53:12 +00:00
values={{
2026-07-28 16:16:26 +00:00
title: pin.title(),
topics: pin.topics(),
2026-07-06 18:53:12 +00:00
value: pinToReference(pin),
2026-07-28 16:16:26 +00:00
content: pin.content(),
2026-07-06 18:53:12 +00:00
}}
2026-06-23 23:30:54 +00:00
{submit} />