flotilla/src/app/components/PinAdd.svelte

38 lines
991 B
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"
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 {setPinReference} from "@app/pinboards"
2026-06-23 23:30:54 +00:00
type Props = {
url: string
address: string
reference?: string
2026-06-23 23:30:54 +00:00
}
const {url, address, reference}: Props = $props()
2026-06-23 23:30:54 +00:00
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).setIdentifier().addBoard(address)
2026-06-23 23:30:54 +00:00
2026-07-28 16:16:26 +00:00
if (!setPinReference(eventWriter, value)) {
return "Please enter a valid URL or nostr link."
}
2026-06-23 23:30:54 +00:00
2026-07-28 16:16:26 +00:00
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="Add Link"
action="Add link"
successMessage="Link added!"
values={{value: reference}}
{submit} />