flotilla/src/app/components/PinEdit.svelte

41 lines
975 B
Svelte
Raw Normal View History

2026-06-23 23:30:54 +00:00
<script lang="ts">
import PinForm, {type PinFormValues} from "@app/components/PinForm.svelte"
import {createPin, referenceToPin, pinToReference, type PublishedPin} from "@app/pinboards"
2026-06-23 23:30:54 +00:00
type Props = {
url: string
pin: PublishedPin
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-06-23 23:30:54 +00:00
const params = referenceToPin(value)
if (!params) return "Please enter a valid URL or nostr link."
// Reuse the pin's identifier and boards so its addressable event is replaced.
return createPin(url, {
...params,
identifier: pin.identifier,
boards: pin.boards,
title,
topics,
2026-07-06 18:53:12 +00:00
description: content,
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={{
title: pin.title,
topics: pin.topics,
value: pinToReference(pin),
content: pin.description,
}}
2026-06-23 23:30:54 +00:00
{submit} />