flotilla/src/app/components/PinEdit.svelte

46 lines
1.2 KiB
Svelte
Raw Normal View History

2026-06-23 23:30:54 +00:00
<script lang="ts">
import {relay} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {Pin} from "@welshman/domain"
import {publish} from "@welshman/app"
2026-07-28 16:16:26 +00:00
import type {PinReader} from "@welshman/domain"
2026-06-23 23:30:54 +00:00
import PinForm, {type PinFormValues} from "@app/components/PinForm.svelte"
import {command, relays, writer} from "@app/core"
2026-07-28 16:16:26 +00:00
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)
.setProtected(await $relays.hasNip(url, 70))
.forceRoutes(relay(url))
2026-07-28 16:16:26 +00:00
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(publish)
2026-07-28 16:16:26 +00:00
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} />